Casting and type checking error #366

Open
takobell opened this Issue Jun 5, 2014 · 0 comments

Projects

None yet

1 participant

@takobell
Contributor
takobell commented Jun 5, 2014

If you use this feed: http://feeds.wired.com/wired/index, the SimplePie_File class's constructor will call

$parsed = SimplePie_Misc::parse_url($url);

Which returns an array of:

'scheme' => 'http',
'authority'  => 'feeds.wired.com',
'path' => '/wired/index',
'query' => '',
'fragment' => '',

The last two (query and fragment) are empty strings because parse_url casts null to a string like so:

return array(
    'scheme' => (string) $iri->scheme,
    'authority' => (string) $iri->authority,
    'path' => (string) $iri->path,
    'query' => (string) $iri->query,
    'fragment' => (string) $iri->fragment
);

The constructor continues and gets to:

$url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);

Which eventually calls:

$iri->get_iri();

That method has this chuck of code:

if ($this->iquery !== null)
{
    $iri .= '?' . $this->iquery;
}
if ($this->ifragment !== null)
{
    $iri .= '#' . $this->ifragment;
}

Notice the explicit check for null when the previous parse_url had cast the null values to empty strings.

This ends up generating a URL as such:

http://feeds.wired.com/wired/index?#

Which leads to a resource not found error.

Changing the code to this, fixes it:

if (!empty($this->iquery))
{
    $iri .= '?' . $this->iquery;
}
if (!empty($this->ifragment))
{
    $iri .= '#' . $this->ifragment;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment