#38 problem with content contructs in atom feeds

open
nobody
None
5
2009-03-08
2009-03-08
maze
No

if you have a atom structure like this:

feed
item
title
Itemtitle
...
source
title
Sourcetitle
...

than the title of source would be concated to the item title which is than incorrectly ItemtitleSourcetitle.
This could happen to every element in $_CONTENT_CONSTRUCTS.
To avoid this I added a check of the element depth.
Here is my diff:

@@ -34,6 +34,7 @@
class MagpieRSS {
var $parser;

+ var $depth;
var $current_item = array(); // item currently being parsed
var $items = array(); // collection of parsed items
var $channel = array(); // hash of channel fields
@@ -144,6 +145,7 @@
}

function feed_start_element($p, $element, &$attrs) {
+ $this->depth++;
$el = $element = strtolower($element);
$attrs = array_change_key_case($attrs, CASE_LOWER);

@@ -207,7 +209,7 @@
}

# handle atom content constructs
- elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) )
+ elseif ( $this->depth < 4 and $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) )
{
// avoid clashing w/ RSS mod_content
if ($el == 'content' ) {
@@ -285,7 +287,7 @@
{
$this->inimage = false;
}
- elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) )
+ elseif ($this->depth < 4 and $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) )
{
$this->incontent = false;
}
@@ -311,6 +313,7 @@
}

$this->current_namespace = false;
+ $this->depth--;
}

best regards
Matze

Discussion

  • maze
    maze
    2009-03-08

    sorry, readable structure:

    feed
    --item
    ----title
    ------Itemtitle
    ----source
    ------title
    --------Sourcetitle
    ...