]> git.wh0rd.org Git - tt-rss.git/commitdiff
feedparser: check if initial xpath query for root element returns anything
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 19 Jun 2013 15:40:36 +0000 (19:40 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 19 Jun 2013 15:40:36 +0000 (19:40 +0400)
classes/feedparser.php

index d93c575b21edbae9931d214eff4eacd3f2aeeaa8..eb8606de912339a5c8ad8d3f9cc278c830b06373 100644 (file)
@@ -51,24 +51,28 @@ class FeedParser {
 
                $this->xpath = $xpath;
 
-               $root = $xpath->query("(//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF)")->item(0);
+               $root = $xpath->query("(//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF)");
 
                if ($root) {
-                       switch (mb_strtolower($root->tagName)) {
-                       case "rdf:rdf":
-                               $this->type = $this::FEED_RDF;
-                               break;
-                       case "channel":
-                               $this->type = $this::FEED_RSS;
-                               break;
-                       case "feed":
-                               $this->type = $this::FEED_ATOM;
-                               break;
-                       default:
-                               if( !isset($this->error) ){
-                                       $this->error = "Unknown/unsupported feed type";
+                       $root = $root->item(0);
+
+                       if ($root) {
+                               switch (mb_strtolower($root->tagName)) {
+                               case "rdf:rdf":
+                                       $this->type = $this::FEED_RDF;
+                                       break;
+                               case "channel":
+                                       $this->type = $this::FEED_RSS;
+                                       break;
+                               case "feed":
+                                       $this->type = $this::FEED_ATOM;
+                                       break;
+                               default:
+                                       if( !isset($this->error) ){
+                                               $this->error = "Unknown/unsupported feed type";
+                                       }
+                                       return;
                                }
-                               return;
                        }
 
                        switch ($this->type) {