Wordpress RSS parser bugs discovered and fixed

July 14, 2008 at 5:02 pm, niflostancu

Hey, niflostancu here, for the first time!

This post is about some bugs I found in Wordpress, actually Scorpiono found them, I only analyzed and fixed them.
Both are on the same feature, the wp_rss function (and it’s dependencies), which allows you to automatically grab and display RSS feeds in your sidebar (somewhat like the upcoming Brutus RSS plugin, but you can’t make posts from them).

The first one is a bug in the MagpieRSS ATOM feed parser, where, on some ATOM feeds, the link is empty (wp-includes/rss.php, lines 186-197).
The other bug affects all types of feeds with non-ISO-8859-1 encoding (including UTF-8, the most used), where some special characters like the pound and euro sign, diacritics etc aren’t shown correctly (htmlentities was used without the UTF-8 encoding parameter, wp-includes/rss.php, lines 850 and 869)

I attached here a fixed rss.php.zip (WP 2.5.1+ ONLY), uncompress it and upload it in wp-includes, replacing the old one. For other versions and if the bugs are not solved, for future versions, here is what I changed:

  • For the first bug, I changed the wp_rss function like this:

    foreach ( $rss->items as $item ) {
       if (!$item['link']) $item['link']=$item['link_']; //added this line

    although I could fix this on class level, MagpieRSS class, feed_start_element function, but I wanted a quick fix that would take effect immediately (wordpress usually caches parsed feeds):

    elseif ($this->feed_type == ATOM and $el == ‘link’ )
    {
       if ( isset($attrs['rel']) and $attrs['rel'] == ‘alternate’ )
    {
        $link_el = ‘link’;
    }
    elseif ( empty($attrs['rel']) ) {$link_el = ‘link’;} // added this line
    else {
        $link_el = ‘link_’ . $attrs['rel'];
    }
    $this->append($link_el, $attrs['href']);
    }

  • For the second you have to search for htmlentities (found only in wp_rss and get_rss functions) and replace the words with attribute_escape:

    attribute_escape( $item['title'] )


6 Comments so far

  1. 1.

    WLD says:

    On July 15, 2008at 11:15 am

    thanks guys, I’ll fix it soon!
    Keep up the good work :)

  2. 2.

    Scorpiono says:

    On July 15, 2008at 12:52 pm

    Cheers! ;)

  3. 3.

    [...] Wordpress RSS parser bugs discovered and fixed [...]

  4. 4.

    G-G says:

    On September 23, 2009at 2:01 pm

    thank so much, it really helpfull

  5. 5.

    Sean Perry says:

    On May 20, 2010at 7:39 pm

    RSS Feeds are really very helpful and you could get site and news updates from it.`’`

  6. 6.

    Zoe Ali says:

    On July 28, 2010at 10:26 am

    RSS feeds are really great because you are always updated with the latest news or blog posts.~*~


6 Responses to “ Wordpress RSS parser bugs discovered and fixed