Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.0.5

Bug #10501 Atom's getLink() should query links without 'rel' in special case.
Submitted: 2007-03-26 00:09 UTC
From: toydi Assigned: jystewart
Status: Closed Package: XML_Feed_Parser (version 1.0.1)
PHP Version: 5.1.6 OS: GNU/Linux
Roadmaps: (Not assigned)    
Subscription  


 [2007-03-26 00:09 UTC] toydi (Teo Hui Ming)
Description: ------------ According to RFC4287 section 4.2.7.2: [..]If the 'rel' attribute is not present, the link element MUST be interpreted as if the link relation type is "alternate". However, in 'XML_Feed_Parser_Atom' class, getLink(0, 'href', array('rel'=>'alternate')) does not search for links that without a 'rel' attribute. The patch below uses a slightly different xpath query to fix the problem. Test script: --------------- $source = <<<XML <?xml version="1.0" ?> <entry xmlns="http://www.w3.org/2005/Atom"> <link href="http://example.org/2005/04/02/atom" /> </entry> XML; $feed = new XML_Feed_Parser($source); $entry = $feed->getEntryByOffset(0); // Output var_dump($entry->link(0, 'href', array('rel'=>'alternate'))); Patch: ---------- diff -u Parser.org/Atom.php Parser/Atom.php --- Parser.org/Atom.php 2007-03-26 07:21:16.000000000 +0800 +++ Parser/Atom.php 2007-03-26 08:46:05.000000000 +0800 @@ -329,12 +329,22 @@ { if (is_array($params) and !empty($params)) { $terms = array(); + $alt_predicate = ''; + $other_predicate = ''; foreach ($params as $key => $value) { - $terms[] = "@$key='$value'"; + if ($key == 'rel' && $value == 'alternate') { + $alt_predicate = '[not(@rel) or @rel="alternate"]'; + } else { + $terms[] = "@$key='$value'"; + } + } + if (!empty($terms)) { + $other_predicate = '[' . join(' and ', $terms) . ']'; } + $query = $this->xpathPrefix + . 'atom:link' . $alt_predicate . $other_predicate; - $query = $this->xpathPrefix . 'atom:link[' . join(' and ', $terms) . ']'; $links = $this->xpath->query($query); } else { $links = $this->model->getElementsByTagName('link'); Expected result: ---------------- Output: string(34) "http://example.org/2005/04/02/atom" Actual result: -------------- Output: bool(false)

Comments

 [2007-03-26 11:49 UTC] jystewart (James Stewart)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.