Call to a member function get_uri() on a non-object in simplepie/library/SimplePie/Misc.php on line 83 #214

Closed
ghost opened this Issue Jul 11, 2012 · 44 comments

Projects

None yet
@ghost
ghost commented Jul 11, 2012

Hi there,

I'm using your very wonderful code but I noticed that I run into this problem:
Call to a member function get_uri() on a non-object in simplepie/library/SimplePie/Misc.php on line 83

I really don't have an idea why this is happening.

Kindly guide me how to fix this one.

Thanks!

@hakimihamdan88

yeah, im getting those error too
cc @rmccue

@Pop-Code

Same here...

@ghost
ghost commented Jul 17, 2012

Yeah, too bad no one is answering here. :(

@ghost
ghost commented Jul 17, 2012

When I enter this URL: http://bfgb.wordpress.com/feed/
I get this error: Fatal error: Call to a member function get_uri() on a non-object in D:\xampp\htdocs\simplepie\library\SimplePie\Misc.php on line 83

What's the problem?!

@Xeoncross

I just got this error using a fresh git checkout on an Ubuntu box.

PHP Fatal error:  Call to a member function get_uri() on a non-object in /path/git/simplepie/library/SimplePie/Misc.php on line 83
PHP Stack trace:
PHP   9. SimplePie_Item->get_permalink() /path/News/Bootstrap.php:89
PHP  10. SimplePie_Item->get_link() /path/git/simplepie/library/SimplePie/Item.php:929
PHP  11. SimplePie_Item->get_links() /path/git/simplepie/library/SimplePie/Item.php:955
PHP  12. SimplePie_Item->get_base() /path/git/simplepie/library/SimplePie/Item.php:1007
PHP  13. SimplePie->get_base() /path/git/simplepie/library/SimplePie/Item.php:167
PHP  14. SimplePie->get_link() /path/git/simplepie/library/SimplePie.php:1922
PHP  15. SimplePie->get_links() /path/git/simplepie/library/SimplePie.php:2270
PHP  16. SimplePie->sanitize() /path/git/simplepie/library/SimplePie.php:2344
PHP  17. SimplePie_Sanitize->sanitize() /path/git/simplepie/library/SimplePie.php:1944
PHP  18. SimplePie_Registry->call() /path/git/simplepie/library/SimplePie/Sanitize.php:359
PHP  19. call_user_func_array() /path/git/simplepie/library/SimplePie/Registry.php:206
PHP  20. SimplePie_Misc::absolutize_url() /path/git/simplepie/library/SimplePie/Registry.php:0

Perhaps change Misc.php since SimplePie_IRI::absolutize can return false.

public static function absolutize_url($relative, $base)
{
    $iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
    // return $iri->get_uri();
    if($iri) return $iri->get_uri();
}

However, making that change results in:

PHP Notice: This XML document is invalid, likely due to invalid characters. XML error: > required at line 1110, column 141 in /home/david/www/git/simplepie/library/SimplePie.php on line 1374
@rmccue
Member
rmccue commented Jul 19, 2012

Thanks for reporting this issue! In future @hakimihamdan88, it's not necessary to CC me as I get notified of all issues automatically. I would have responded sooner, but it has been a busy week. :)

I'll take a look into this. @gsnedders, want to check this when you check #219? This also seems like somewhere we need unit tests too.

For those reporting this issue: can you var_dump() the parameters being passed in to SimplePie_Misc::absolutize_url() please?

@ghost
ghost commented Jul 20, 2012

public static function absolutize_url($relative, $base)
{
$iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
return $iri->get_uri();
}

That is where the error happens. When I try to var dump $relative and $base using this feed: http://bfgb.wordpress.com/feed/,
This are the results:
var_dump($relative)
Result:
string(31) "http://bfgb.wordpress.com/feed/"
string(31) "http://bfgb.wordpress.com/feed/"
string(31) "http://bfgb.wordpress.com/feed/"
string(33) "http://bfgb.wordpress.com/osd.xml"
string(31) "http://bfgb.wordpress.com/feed/"
string(40) "http://bfgb.wordpress.com/?pushpress=hub"
string(31) "http://bfgb.wordpress.com/feed/"
string(25) "http://bfgb.wordpress.com"Blogging for a Good Book
Fatal error: Call to a member function get_uri() on a non-object in D:\xampp\htdocs\simplepie\library\SimplePie\Misc.php on line 84

var_dump($base)
Result:
string(0) ""
string(31) "http://bfgb.wordpress.com/feed/"
string(0) ""
string(31) "http://bfgb.wordpress.com/feed/"
string(0) ""
string(31) "http://bfgb.wordpress.com/feed/"
string(0) ""
string(31) "http://bfgb.wordpress.com/feed/"Blogging for a Good Book
string(26) "http://bfgb.wordpress.com/" string(0) ""
Fatal error: Call to a member function get_uri() on a non-object in D:\xampp\htdocs\simplepie\library\SimplePie\Misc.php on line 84

The error happens when this code is being run return $iri->get_uri();

Your help would be greatly appreciated since we are already using your library in our live site.

Thanks!

@woody0130

Is there any workaround ?

I am getting this error on $item->get_content() as well:

get_items() as $item): ?> get_permalink(); ?> get_title(); ?>

Posted on get_date('j F Y | g:i a'); ?>

get_content(); ?>
@mazard
mazard commented Jul 22, 2012

Same problem here.

base:http://www.mnac.cat/?lan=002
relative:http://www.flickr.com//photos/73401757@N05/sets/72157630431743284/show/

It looks like there is a problem in the url validation, I think in my case the problem is the '@'.

As a fast workaround I replaced the is_valid function to return always true.

public function is_valid()
{
        return true;
    }

It seems to work fine, I don't know if it can cause any other problems but its not breaking my production site at least.

Regards!
mazard

@ghost
ghost commented Jul 23, 2012

@mazard Is that the function in the IRI.php?
This is the function

public function is_valid()
{
$isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null;
if ($this->ipath !== '' &&
(
$isauthority && (
$this->ipath[0] !== '/' ||
substr($this->ipath, 0, 2) === '//'
) ||
(
$this->scheme === null &&
!$isauthority &&
strpos($this->ipath, ':') !== false &&
(strpos($this->ipath, '/') === false ? true : strpos($this->ipath, ':') < strpos($this->ipath, '/'))
)
)
)
{
return false;
}

return true;

}

I remove everything but retained return true, but the error still exists :(

@nightowl77

Hi

Also having the same problem and wanted to provide some debug text. SimplePie died on this specific entry from engadget

<item>
<title>
<![CDATA[
Huawei's MediaPad 10 teases all of its traits in soothing promo video
]]>
</title>
<link>
http://www.engadget.com/2012/07/22/huawei-mediapad-10-fhd-tablet-teaser/
</link>
<guid isPermaLink="true">
http://www.engadget.com/2012/07/22/huawei-mediapad-10-fhd-tablet-teaser/
</guid>
<comments>
http://www.engadget.com/2012/07/22/huawei-mediapad-10-fhd-tablet-teaser/#comments
</comments>
<description>
<![CDATA[
<p style="text-align: center;"> <a href="http://www.engadget.com/2012/07/22/huawei-mediapad-10-fhd-tablet-teaser/"><img alt="Huawei's MediaPad 10 teases all its traits in soothing promo video" data-src-height="354" data-src-width="567" src="http://www.blogcdn.com/www.engadget.com/media/2012/07/mediapad7-21.png" style="margin: 4px;" /></a></p><p> Huawei's 10-inch FHD tablet has been anything but shy since its little-known <a href="http://www.engadget.com/2012/02/21/huawei-alleged-10-inch-android-tablet-leaks/">early days</a>, well before <a href="http://www.engadget.com/2012/02/26/huawei-mediapad-10-eyes-on/">its unexpected introduction</a> to the masses. But since we've now seen it (<a href="http://www.engadget.com/2012/05/08/huawei-10-inch-mediapad-hands-on/">and felt it</a>) in most of its glory, we shouldn't be surprised that <a href="http://www.engadget.com/tag/Huawei/">its creator's</a> taken the time to put together a quick promotional vid ahead of an expected launch next month. The MediaPad 10 teaser, naturally, touts many of the slate's own features, including the sensational 1920 x 1200 IPS display, Huawei's <a href="http://www.engadget.com/2012/02/26/huawei-adds-home-grown-k3v2-quad-core-mobile-cpu-to-its-arsenal/">in-house K3 Balong CPU</a>, as well as its "refined metallic surface" and "luxurious yet subtle" design. Of course, there's <em>a lot</em> more where that came from, so head on past the break to watch the ballyhooed clip for yourself.</p><p><a href="http://www.engadget.com/2012/07/22/huawei-mediapad-10-fhd-tablet-teaser/" rel="bookmark">Continue reading <em>Huawei's MediaPad 10 teases all of its traits in soothing promo video</em></a></p><p>Filed under: <a href="http://www.engadget.com/category/tabletpcs/" rel="tag">Tablet PCs</a></p><p style="padding:5px;background:#ddd;border:1px solid #ccc;clear:both;"><a href="http://www.engadget.com/2012/07/22/huawei-mediapad-10-fhd-tablet-teaser/">Huawei's MediaPad 10 teases all of its traits in soothing promo video</a> originally appeared on <a href="http://www.engadget.com">Engadget</a> on Sun, 22 Jul 2012 01:13:00 EDT. Please see our <a href="http://www.weblogsinc.com/feed-terms/">terms for use of feeds</a>.</p><h6 style="clear: both; padding: 8px 0 0 0; height: 2px; font-size: 1px; border: 0; margin: 0; padding: 0;"></h6><a href="http://www.engadget.com/2012/07/22/huawei-mediapad-10-fhd-tablet-teaser/" rel="bookmark" title="Permanent link to this entry">Permalink</a>&nbsp;<img class="img_label" src="http://www.blogsmithmedia.com/www.engadget.com/media/post_label_VIA.gif" alt=""/><span class="caption"><a href="http://http://www.ubergizmo.com/2012/07/huawei-mediapad-10-1-gets-a-new-teaser/" target="_blank">Ubergizmo</a><!--//--></span> &nbsp;|&nbsp; <img class="img_label" src="http://www.blogsmithmedia.com/www.engadget.com/media/post_label_source.gif" alt="source"/><span class="caption"><a href="http://www.youtube.com/watch?v=yM9TlNjJ-ss&amp;feature=player_embedded#%21" target="_blank">Huawei (YouTube)</a><!--//--></span> &nbsp;|&nbsp;<a href="http://www.engadget.com/forward/20283290/" title="Send this entry to a friend via email">Email this</a>&nbsp;|&nbsp;<a href="http://www.engadget.com/2012/07/22/huawei-mediapad-10-fhd-tablet-teaser/#comments" title="View reader comments on this entry">Comments</a>
]]>
</description>
<category>Android</category>
<category>Huawei</category>
<category>Huawei MediaPad</category>
<category>Huawei MediaPad 10</category>
<category>Huawei MediaPad 10 FHD</category>
<category>HuaweiMediapad</category>
<category>HuaweiMediapad10</category>
<category>HuaweiMediapad10Fhd</category>
<category>Ice Cream Sandwich</category>
<category>IceCreamSandwich</category>
<category>MediaPad</category>
<category>MediaPad 10</category>
<category>MediaPad 10FHD</category>
<category>Mediapad10</category>
<category>Mediapad10fhd</category>
<category>minipost</category>
<category>video</category>
<dc:creator>
<![CDATA[ Edgar Alvarez ]]>
</dc:creator>
<pubDate>Sun, 22 Jul 2012 01:13:00 EDT</pubDate>
</item>

I think it chokes on that %21 at the end of the "embed youtube" link

Hope this helps!

@woody0130

is there an ETA on a fix for this? My customer is getting very anxious...

@booruguru

I'm having the same problem with the feed --- http://rss.cbc.ca/lineup/topstories.xml

Note: The error is preventing my page from fully rendering. Any suggestions on how I force the page to load fully despite this (or any future) errors?

@cookiejest

Hi,

I think this problem is being caused if the URL contains numbers for some reason.

My code works with other feeds that have no numbers but not with http://rss.cnn.com/rss/edition_business360.rss

With this feed I get the error quoted above.

@ghost
ghost commented Jul 29, 2012

@cookiejest But I'm getting the error when using this URL: http://bfgb.wordpress.com/feed/ that doesn't have a number.

@cookiejest

@jimgym1989 yours has a space in one of the URLs I think

@ghost
ghost commented Jul 29, 2012

@cookiejest What URL? I'm not seeing that one that has a space. Hmmm...

@cookiejest

@jimgym1989 string(31) "http://bfgb.wordpress.com/feed/"Blogging for a Good Book

But I don't really know

@ghost
ghost commented Jul 29, 2012

@cookiejest Did you try that in your end? Did it also get the same error?

@ghost
ghost commented Jul 29, 2012

@cookiejest The weird thing is that when we try to add those URLs on their simplepie demo (http://simplepie.org/demo/), it's not giving us error, is this a server issue? like our server messes everything. But the error doesn't look like a server error or issue.

I wonder when those simplepie developers will fixed this problem.

@cookiejest

@jimgym1989 http://bfgb.wordpress.com/feed/ doesnt work on my set up either as it gives me the error. This is a problem with SimplePie code.

@ghost
ghost commented Jul 29, 2012

@cookiejest Try putting that URL in http://simplepie.org/demo/, it's not giving that error.

@cookiejest

@jimgym1989 I see that it works using that, will have to wait for them to try and fix it as I don't understand SimplePie well enough to suggest a way to solve it without causing other problems

@cosenal
cosenal commented Jul 30, 2012

I don't if it can help to debug. This feed create the issue in my case: http://lucatrevisan.wordpress.com/feed/
I am using SP 1.3

@hakimihamdan88

its seems @rmccue is busy guys

@ghost
ghost commented Aug 2, 2012

We're doomed! :(

@Hunin
Hunin commented Aug 3, 2012

I added a ? to the function call replace_invalid_with_pct_encoding. I was passing a query string to break cache on the website where I pull the RSS feed. I think it would also work if you added a % which is the invalid character.

line 1062 @ IRI.php

    else
    {
        $valid = $this->replace_invalid_with_pct_encoding($ipath, '!$&\'()*+,;=@:/');
        $removed = $this->remove_dot_segments($valid);

        $cache[$ipath] = array($valid, $removed);
        $this->ipath =  ($this->scheme !== null) ? $removed : $valid;
    }

This is just a workaround and not any sort of fix. There seems to be something not being handled by replace_invalid_with_pct_encoding and thus it isn't normalizing the URL completely.

@ghost
ghost commented Aug 4, 2012

I get this problem too when using SimplePie_FIle with a path that has dots in it. e.g. DIR . '/../fixtures/test-data.xml';

This is caused by line 1065 @ IRI.php

$removed = $this->remove_dot_segments($valid);
@ghost
ghost commented Aug 6, 2012

@Hunin : I wonder what's wrong with this URL: http://bfgb.wordpress.com/feed/ It's giving me those error. It seemed like there's no malicious characters on that URL.

Have you tried entering your URL on their demo site? Looks like their demo site won't show any errors and works perfectly

@Hunin
Hunin commented Aug 6, 2012

@jimgym1989 It looks like SimplePie processes every URL in the feed using set_path function. In your feed, you have some URLs with a ? character like <atom:link rel='hub' href='http://bfgb.wordpress.com/?pushpress=hub'/> on line 29 and <media:content url="http://bfgb.files.wordpress.com/2012/07/europe.jpeg?w=200" medium="image"> on line 63. So I believe adding a ? character to the extra characters of the function replace_invalid_with_pct_encoding will bypass these characters.

@ghost
ghost commented Aug 7, 2012

@Hunin I added a ? on that call

$valid = $this->replace_invalid_with_pct_encoding($ipath, '!$&\'()*+,;=@:/?');

but still it gives me error

@iSenne
iSenne commented Aug 9, 2012

I have the same problem. Temporarily solved it by returning true in the is_valid() function! But will watch for a solution!

@cosenal
cosenal commented Aug 10, 2012

@iSenne: temporarily solved in what sense? I did the same, but I still get the Fatal Error :(

@cmmartin

This is a strange issue. I have been parsing the same feeds for weeks without any problems and now I am getting this error on many of my feeds. Is anyone working on this? Seems like the Simplepie guys may have abandoned it

@rmccue
Member
rmccue commented Aug 13, 2012

@cmmartin I'm definitely watching this issue, but I've not yet had time to track it down. If anyone can take one of these broken feeds and break it down to just the part causing the error, that would help immensely.

@ghost
ghost commented Aug 13, 2012

@rmccue That's the problem, I personally don't know the reason why this feed http://bfgb.wordpress.com/feed/ broke up, @Hunin told me that that's because I have some URLs with a ? character like on line 29 and on line 63.

Kindly work on this one please, we are already moving our site in live so that's why we needed to find a solution for this one. I know you're kinda busy on your job, but please, kindly make time for this one. Have mercy!

Thanks @rmccue! Your help would be greatly appreciated! :)

@iSenne
iSenne commented Aug 13, 2012

@zimba12 The is_valid() function can either return false or true. I changed the false in to true and that solved my problem, like @mazard did!

@demoncheese

To stop the error from appearing I just added a check to see if the object was created and pass the result of the method if it is and false if not so the absolutize_url method in Misc.php became:

public static function absolutize_url($relative, $base)
{
    $iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
    if ( is_object( $iri ) )
        return $iri->get_uri();
    else {
        return FALSE;
    }
}

This seems to be working for me now

@cosenal
cosenal commented Aug 17, 2012

@iSenne: are you talking about the function is_valid() in IRI.php? Nothing changes here if I change the false into true.

@cosenal
cosenal commented Aug 19, 2012

Some var_dump that can help debugging.

For many feeds, the error arises when the values passed to absolutize_url are:
string(0) ""
string(0) ""

There are other cases too. For example, for the feed http://projectprime.org/projectprime/feed.php the var_dump on $relative and $base before the absolutize_url gives, respectively:

string(46) "http://projectprime.org//data/comic/en/301.png"
string(39) "http://projectprime.org/project%20prime"

Maybe in this case the double slash is what creates issues?

@ghost
ghost commented Aug 21, 2012

@demoncheese : wow that one worked for me, but I got a feeling that that's just a temporary fix, I hope @rmccue or the simplePie guys would do some unit testing.

Thanks!

@casta
casta commented Aug 23, 2012

Please, see the pull request I just issued. This is the fix I use: #228

@hakimihamdan88

any updates?

@rmccue
Member
rmccue commented Oct 30, 2012

Looks like I have a test case: when the path component begins with "//"

@rmccue rmccue added a commit that referenced this issue Oct 30, 2012
@rmccue rmccue Fix issue #214 by ensuring we handle invalid URIs
Also closes #228, but doesn't fix the base problem where paths starting
with // aren't parsed by SimplePie_IRI.
267e396
@rmccue rmccue added a commit that referenced this issue Oct 30, 2012
@rmccue rmccue Fix issue #214 by ensuring we handle invalid URIs
Also closes #228, but doesn't fix the base problem where paths starting
with // aren't parsed by SimplePie_IRI.
7e6ae7c
@rmccue rmccue closed this Oct 30, 2012
@zeehio zeehio referenced this issue in campino2k/leDashboard Oct 5, 2013
Closed

Updated simplepie (bugfix) and README #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment