• 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 = "";
        $current;
        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);
            }
            else
            {
                $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?

    Thanks!

  • The topic ‘Editing core file: SimplePie parsing chokes on entity’ is closed to new replies.