Editing core file: SimplePie parsing chokes on entity (1 post)

  1. Shasta
    Posted 4 years ago #

    I need to consume an RSS feed being generated by ColdFusion which occasionally contains a malformed entity. Fixing all the input isn't an option.

    It works when I add this function to class-feed.php:

    function stripInvalidXml($value)
        $ret = "";
        if (empty($value))
            return $ret;
        $length = strlen($value);
        for ($i=0; $i < $length; $i++)
            $current = ord($value{$i});
            if (($current == 0x9) ||
                ($current == 0xA) ||
                ($current == 0xD) ||
                (($current >= 0x20) && ($current <= 0xD7FF)) ||
                (($current >= 0xE000) && ($current <= 0xFFFD)) ||
                (($current >= 0x10000) && ($current <= 0x10FFFF)))
                $ret .= chr($current);
                $ret .= " ";
        return $ret;

    And then add a call to it before parsing in the class declaration in the same file:

    class WP_SimplePie_File extends SimplePie_File {
    //bunch of code
    $this->body = stripInvalidXml(wp_remote_retrieve_body( $res ));
    //rest of function

    I'd like to extract these changes so they won't break on the next update of WordPress, but simply overriding the class in functions.php seems unlikely to do what I expect. I could write my own class with a slightly different name..but I'd still have to change the core files to call that instead of WP_SimplePie_File, so it only moves the problem.

    What's the right way to do this? Also, since SimplePie seems to be dead, is there an up and coming approach to RSS I should be aware of? Is this all going to break in a soon-to-be version anyway?


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.