From a9000b03443d64ac5d7137c868862a5e1496e871 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 19 Jun 2013 19:40:36 +0400 Subject: feedparser: check if initial xpath query for root element returns anything --- classes/feedparser.php | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'classes/feedparser.php') diff --git a/classes/feedparser.php b/classes/feedparser.php index d93c575b2..eb8606de9 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -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) { -- cgit v1.2.3-54-g00ecf From 4f00f55ca2ecd2e5a75c2c4ef37ca0e1143a7ac7 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 11 Jul 2013 15:40:09 +0400 Subject: parser: add charset recoding hack for systems where libxml is build without support for iconv (handles libxml error 32) --- classes/feedparser.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'classes/feedparser.php') diff --git a/classes/feedparser.php b/classes/feedparser.php index eb8606de9..53f6c52a9 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -20,6 +20,24 @@ class FeedParser { $error = libxml_get_last_error(); + // libxml compiled without iconv? + if ($error && $error->code == 32) { + if (preg_match('/^(<\\?xml .*?)encoding="(.+?)"(.*?\\?>)/', $data, $matches) === 1) { + libxml_clear_errors(); + + $enc = $matches[2]; + + $data = iconv($enc, 'UTF-8//IGNORE', $data); + $data = preg_replace('/^<\\?xml .*?\\?>/', $matches[1] . $matches[3] , $data); + + $this->doc = new DOMDocument(); + $this->doc->loadXML($data); + + $error = libxml_get_last_error(); + } + } + + // some terrible invalid unicode entity? if ($error && $error->code == 9) { libxml_clear_errors(); -- cgit v1.2.3-54-g00ecf From f8160106af762da1a2f4b4a2579b8165cb2005e2 Mon Sep 17 00:00:00 2001 From: wltb Date: Mon, 15 Jul 2013 00:25:45 +0200 Subject: Feedparser/encoding change: More general regular expression, set encoding to UTF-8 explicitly --- classes/feedparser.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'classes/feedparser.php') diff --git a/classes/feedparser.php b/classes/feedparser.php index 53f6c52a9..651ee010f 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -22,13 +22,13 @@ class FeedParser { // libxml compiled without iconv? if ($error && $error->code == 32) { - if (preg_match('/^(<\\?xml .*?)encoding="(.+?)"(.*?\\?>)/', $data, $matches) === 1) { + if (preg_match('/^(<\?xml[\t\n\r ].*?encoding=["\'])(.+?)(["\'].*?\?>)/s', $data, $matches) === 1) { libxml_clear_errors(); $enc = $matches[2]; - $data = iconv($enc, 'UTF-8//IGNORE', $data); - $data = preg_replace('/^<\\?xml .*?\\?>/', $matches[1] . $matches[3] , $data); + $data = iconv($enc, 'UTF-8//IGNORE', $data); + $data = preg_replace('/^<\?xml[\t\n\r ].*?\?>/s', $matches[1] . "UTF-8" . $matches[3] , $data); $this->doc = new DOMDocument(); $this->doc->loadXML($data); -- cgit v1.2.3-54-g00ecf From f612dbe8a097544cdb06e08f528b43195e911670 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 3 Aug 2013 14:45:27 +0400 Subject: improve support for feeds with invalid unicode entities --- classes/feedparser.php | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'classes/feedparser.php') diff --git a/classes/feedparser.php b/classes/feedparser.php index 651ee010f..4a2c6c2da 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -18,36 +18,46 @@ class FeedParser { $this->doc = new DOMDocument(); $this->doc->loadXML($data); + mb_substitute_character("none"); + $error = libxml_get_last_error(); // libxml compiled without iconv? - if ($error && $error->code == 32) { + if ($error && ($error->code == 32 || $error->code == 9)) { if (preg_match('/^(<\?xml[\t\n\r ].*?encoding=["\'])(.+?)(["\'].*?\?>)/s', $data, $matches) === 1) { - libxml_clear_errors(); - $enc = $matches[2]; - $data = iconv($enc, 'UTF-8//IGNORE', $data); + $data = mb_convert_encoding($data, 'UTF-8', $enc); + $data = preg_replace('/^<\?xml[\t\n\r ].*?\?>/s', $matches[1] . "UTF-8" . $matches[3] , $data); - $this->doc = new DOMDocument(); - $this->doc->loadXML($data); - $error = libxml_get_last_error(); + // apparently not all UTF-8 characters are valid for XML + $data = preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $data); + + if ($data) { + libxml_clear_errors(); + + $this->doc = new DOMDocument(); + $this->doc->loadXML($data); + + $error = libxml_get_last_error(); + } } } // some terrible invalid unicode entity? if ($error && $error->code == 9) { - libxml_clear_errors(); + $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8'); - // we might want to try guessing input encoding here too - $data = iconv("UTF-8", "UTF-8//IGNORE", $data); + if ($data) { + libxml_clear_errors(); - $this->doc = new DOMDocument(); - $this->doc->loadXML($data); + $this->doc = new DOMDocument(); + $this->doc->loadXML($data); - $error = libxml_get_last_error(); + $error = libxml_get_last_error(); + } } $this->error = $this->format_error($error); -- cgit v1.2.3-54-g00ecf From 5fa36a640168d3eaf27f3d6630ffd71527bcd724 Mon Sep 17 00:00:00 2001 From: wltb Date: Mon, 9 Sep 2013 00:44:55 +0200 Subject: Feedparser: Change handling of libxml error 9 (cycle all errors) --- classes/feedparser.php | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'classes/feedparser.php') diff --git a/classes/feedparser.php b/classes/feedparser.php index 4a2c6c2da..22052bdb6 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -23,18 +23,12 @@ class FeedParser { $error = libxml_get_last_error(); // libxml compiled without iconv? - if ($error && ($error->code == 32 || $error->code == 9)) { - if (preg_match('/^(<\?xml[\t\n\r ].*?encoding=["\'])(.+?)(["\'].*?\?>)/s', $data, $matches) === 1) { - $enc = $matches[2]; - - $data = mb_convert_encoding($data, 'UTF-8', $enc); + if ($error && $error->code == 32) { + if (preg_match('/^(<\?xml[\t\n\r ].*?encoding[\t\n\r ]*=[\t\n\r ]*["\'])(.+?)(["\'].*?\?>)/s', $data, $matches) === 1) { + $data = mb_convert_encoding($data, 'UTF-8', $matches[2]); $data = preg_replace('/^<\?xml[\t\n\r ].*?\?>/s', $matches[1] . "UTF-8" . $matches[3] , $data); - - // apparently not all UTF-8 characters are valid for XML - $data = preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $data); - if ($data) { libxml_clear_errors(); @@ -43,20 +37,29 @@ class FeedParser { $error = libxml_get_last_error(); } - } + } } // some terrible invalid unicode entity? - if ($error && $error->code == 9) { - $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8'); + if ($error) { + foreach(libxml_get_errors() as $err) { + if ($err->code == 9) { + // remove dangling bytes + $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8'); + + // apparently not all UTF-8 characters are valid for XML + $data = preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $data); - if ($data) { - libxml_clear_errors(); + if ($data) { + libxml_clear_errors(); - $this->doc = new DOMDocument(); - $this->doc->loadXML($data); + $this->doc = new DOMDocument(); + $this->doc->loadXML($data); - $error = libxml_get_last_error(); + $error = libxml_get_last_error(); + } + break; + } } } -- cgit v1.2.3-54-g00ecf From d3305ff8de6ca9881021646221827d27240dba38 Mon Sep 17 00:00:00 2001 From: wltb Date: Tue, 24 Sep 2013 16:43:47 +0200 Subject: Feedparser: Only format fatal errors --- classes/feedparser.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'classes/feedparser.php') diff --git a/classes/feedparser.php b/classes/feedparser.php index 22052bdb6..07de73a9d 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -62,8 +62,16 @@ class FeedParser { } } } - - $this->error = $this->format_error($error); + + $this->error = ""; + if($error) { + foreach(libxml_get_errors() as $error) { + if($error->level == LIBXML_ERR_FATAL) { + $this->error = $this->format_error($error); + break; //break here because currently we only show one error + } + } + } libxml_clear_errors(); $this->items = array(); -- cgit v1.2.3-54-g00ecf From 4d49863f65e14190c8e460700f2bd197e724666c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 25 Sep 2013 14:26:45 +0400 Subject: fix style in feedparser --- classes/feedparser.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'classes/feedparser.php') diff --git a/classes/feedparser.php b/classes/feedparser.php index 07de73a9d..2942fb27d 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -42,11 +42,11 @@ class FeedParser { // some terrible invalid unicode entity? if ($error) { - foreach(libxml_get_errors() as $err) { + foreach (libxml_get_errors() as $err) { if ($err->code == 9) { // remove dangling bytes $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8'); - + // apparently not all UTF-8 characters are valid for XML $data = preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $data); @@ -62,15 +62,15 @@ class FeedParser { } } } - + $this->error = ""; - if($error) { - foreach(libxml_get_errors() as $error) { - if($error->level == LIBXML_ERR_FATAL) { + if ($error) { + foreach (libxml_get_errors() as $error) { + if ($error->level == LIBXML_ERR_FATAL) { $this->error = $this->format_error($error); break; //break here because currently we only show one error } - } + } } libxml_clear_errors(); -- cgit v1.2.3-54-g00ecf From 54f23d38a6d9e994575d2159b2277674149ae5d8 Mon Sep 17 00:00:00 2001 From: wltb Date: Thu, 26 Sep 2013 19:56:45 +0200 Subject: Feedparser: Store libXML fatal error messages in an array, repair error reporting --- classes/feedparser.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'classes/feedparser.php') diff --git a/classes/feedparser.php b/classes/feedparser.php index 2942fb27d..4eaeb2429 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -2,6 +2,7 @@ class FeedParser { private $doc; private $error; + private $libxml_errors = array(); private $items; private $link; private $title; @@ -63,12 +64,12 @@ class FeedParser { } } - $this->error = ""; if ($error) { foreach (libxml_get_errors() as $error) { if ($error->level == LIBXML_ERR_FATAL) { - $this->error = $this->format_error($error); - break; //break here because currently we only show one error + if(!isset($this->error)) //currently only the first error is reported + $this->error = $this->format_error($error); + $this->libxml_errors [] = $this->format_error($error); } } } @@ -216,6 +217,10 @@ class FeedParser { return $this->error; } + function errors() { + return $this->libxml_errors; + } + function get_link() { return $this->link; } -- cgit v1.2.3-54-g00ecf From 2c6f3c2eb304c227bbb1d4bbbf1df8a9879715b1 Mon Sep 17 00:00:00 2001 From: wltb Date: Fri, 27 Sep 2013 00:13:55 +0200 Subject: Feedparser: Add important check for unknown feed type detection --- classes/feedparser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes/feedparser.php') diff --git a/classes/feedparser.php b/classes/feedparser.php index 4eaeb2429..1c97e496b 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -93,7 +93,7 @@ class FeedParser { $root = $xpath->query("(//atom03:feed|//atom:feed|//channel|//rdf:rdf|//rdf:RDF)"); - if ($root) { + if ($root && $root->length > 0) { $root = $root->item(0); if ($root) { -- cgit v1.2.3-54-g00ecf From 4ad04ee227dd7d704f417aaf9d6762f5cfdf4c1f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 29 Oct 2013 12:15:26 +0400 Subject: report all libxml errors in updater debug output force utf8 encoding if devforceupdate is on parser: try to convert non-unicode feeds with specified encoding to utf8 before trying to remove dangling utf8 characters in case of utf8-related libxml errors because doing so produces garbage content --- classes/feedparser.php | 29 +++++++++++++++++++---------- classes/feeds.php | 2 +- include/rssfuncs.php | 8 +++++++- 3 files changed, 27 insertions(+), 12 deletions(-) (limited to 'classes/feedparser.php') diff --git a/classes/feedparser.php b/classes/feedparser.php index 1c97e496b..de6c56542 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -13,6 +13,16 @@ class FeedParser { const FEED_RSS = 1; const FEED_ATOM = 2; + function normalize_encoding($data) { + if (preg_match('/^(<\?xml[\t\n\r ].*?encoding[\t\n\r ]*=[\t\n\r ]*["\'])(.+?)(["\'].*?\?>)/s', $data, $matches) === 1) { + $data = mb_convert_encoding($data, 'UTF-8', $matches[2]); + + $data = preg_replace('/^<\?xml[\t\n\r ].*?\?>/s', $matches[1] . "UTF-8" . $matches[3] , $data); + } + + return $data; + } + function __construct($data) { libxml_use_internal_errors(true); libxml_clear_errors(); @@ -25,19 +35,15 @@ class FeedParser { // libxml compiled without iconv? if ($error && $error->code == 32) { - if (preg_match('/^(<\?xml[\t\n\r ].*?encoding[\t\n\r ]*=[\t\n\r ]*["\'])(.+?)(["\'].*?\?>)/s', $data, $matches) === 1) { - $data = mb_convert_encoding($data, 'UTF-8', $matches[2]); - - $data = preg_replace('/^<\?xml[\t\n\r ].*?\?>/s', $matches[1] . "UTF-8" . $matches[3] , $data); + $data = $this->normalize_encoding($data); - if ($data) { - libxml_clear_errors(); + if ($data) { + libxml_clear_errors(); - $this->doc = new DOMDocument(); - $this->doc->loadXML($data); + $this->doc = new DOMDocument(); + $this->doc->loadXML($data); - $error = libxml_get_last_error(); - } + $error = libxml_get_last_error(); } } @@ -45,6 +51,9 @@ class FeedParser { if ($error) { foreach (libxml_get_errors() as $err) { if ($err->code == 9) { + // if the source feed is not in utf8, next conversion will fail + $data = $this->normalize_encoding($data); + // remove dangling bytes $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8'); diff --git a/classes/feeds.php b/classes/feeds.php index 7f5fd10af..2c17a2257 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -148,7 +148,7 @@ class Feeds extends Handler_Protected { $override_order = false, $include_children = false) { if (isset($_REQUEST["DevForceUpdate"])) - header("Content-Type: text/plain"); + header("Content-Type: text/plain; charset=utf-8"); $disable_cache = false; diff --git a/include/rssfuncs.php b/include/rssfuncs.php index bfbec0919..bc6048217 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -1110,7 +1110,13 @@ $error_msg = db_escape_string(mb_substr($rss->error(), 0, 245)); - _debug("error fetching feed: $error_msg", $debug_enabled); + _debug("fetch error: $error_msg", $debug_enabled); + + if (count($rss->errors()) > 1) { + foreach ($rss->errors() as $error) { + _debug("+ $error"); + } + } db_query( "UPDATE ttrss_feeds SET last_error = '$error_msg', -- cgit v1.2.3-54-g00ecf From d71ac5d3dabde7dda4aef6efa2af3a68ee2095c6 Mon Sep 17 00:00:00 2001 From: wltb Date: Wed, 18 Dec 2013 17:05:43 +0100 Subject: implemented get_comments_url() and Atom Threading Extension --- classes/feeditem/common.php | 17 +++++++++++++++-- classes/feedparser.php | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'classes/feedparser.php') diff --git a/classes/feeditem/common.php b/classes/feeditem/common.php index 58065b198..80bebf8fb 100644 --- a/classes/feeditem/common.php +++ b/classes/feeditem/common.php @@ -44,13 +44,26 @@ abstract class FeedItem_Common extends FeedItem { } } - // todo function get_comments_url() { + //RSS only. Use a query here to avoid namespace clashes (e.g. with slash). + //might give a wrong result if a default namespace was declared (possible with XPath 2.0) + $com_url = $this->xpath->query("comments", $this->elem)->item(0); + if($com_url) + return $com_url->nodeValue; + + //Atom Threading Extension (RFC 4685) stuff. Could be used in RSS feeds, so it's in common. + //'text/html' for type is too restrictive? + $com_url = $this->xpath->query("atom:link[@rel='replies' and contains(@type,'text/html')]/@href", $this->elem)->item(0); + + if($com_url) + return $com_url->nodeValue; } function get_comments_count() { - $comments = $this->xpath->query("slash:comments", $this->elem)->item(0); + //also query for ATE stuff here + $query = "slash:comments|thread:total|atom:link[@rel='replies']/@thread:count"; + $comments = $this->xpath->query($query, $this->elem)->item(0); if ($comments) { return $comments->nodeValue; diff --git a/classes/feedparser.php b/classes/feedparser.php index de6c56542..187875b5f 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -97,6 +97,7 @@ class FeedParser { $xpath->registerNamespace('slash', 'http://purl.org/rss/1.0/modules/slash/'); $xpath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/'); $xpath->registerNamespace('content', 'http://purl.org/rss/1.0/modules/content/'); + $xpath->registerNamespace('thread', 'http://purl.org/syndication/thread/1.0'); $this->xpath = $xpath; -- cgit v1.2.3-54-g00ecf From b69d94eeeb6ed539267a4328265354a45d23ba86 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Mar 2014 21:04:28 +0400 Subject: parser: experimentally set preservewhitespace to false --- classes/feedparser.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'classes/feedparser.php') diff --git a/classes/feedparser.php b/classes/feedparser.php index 187875b5f..efef3bca4 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -27,6 +27,7 @@ class FeedParser { libxml_use_internal_errors(true); libxml_clear_errors(); $this->doc = new DOMDocument(); + $this->doc->preserveWhiteSpace = false; $this->doc->loadXML($data); mb_substitute_character("none"); @@ -41,6 +42,7 @@ class FeedParser { libxml_clear_errors(); $this->doc = new DOMDocument(); + $this->doc->preserveWhiteSpace = false; $this->doc->loadXML($data); $error = libxml_get_last_error(); @@ -64,6 +66,7 @@ class FeedParser { libxml_clear_errors(); $this->doc = new DOMDocument(); + $this->doc->preserveWhiteSpace = false; $this->doc->loadXML($data); $error = libxml_get_last_error(); -- cgit v1.2.3-54-g00ecf From 4ce778677ef16353d5b0b8342a29bd65575310f5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 4 Mar 2014 16:30:46 +0400 Subject: Revert "parser: experimentally set preservewhitespace to false" This reverts commit b69d94eeeb6ed539267a4328265354a45d23ba86. --- classes/feedparser.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'classes/feedparser.php') diff --git a/classes/feedparser.php b/classes/feedparser.php index efef3bca4..187875b5f 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -27,7 +27,6 @@ class FeedParser { libxml_use_internal_errors(true); libxml_clear_errors(); $this->doc = new DOMDocument(); - $this->doc->preserveWhiteSpace = false; $this->doc->loadXML($data); mb_substitute_character("none"); @@ -42,7 +41,6 @@ class FeedParser { libxml_clear_errors(); $this->doc = new DOMDocument(); - $this->doc->preserveWhiteSpace = false; $this->doc->loadXML($data); $error = libxml_get_last_error(); @@ -66,7 +64,6 @@ class FeedParser { libxml_clear_errors(); $this->doc = new DOMDocument(); - $this->doc->preserveWhiteSpace = false; $this->doc->loadXML($data); $error = libxml_get_last_error(); -- cgit v1.2.3-54-g00ecf From 31bd6f7643bf139802a224f4584caca3cbbcc9b8 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 4 Mar 2014 16:38:04 +0400 Subject: parser: trim some some feed-extracted data link titles and links --- classes/feeditem/atom.php | 10 +++++----- classes/feeditem/rss.php | 12 ++++++------ classes/feedparser.php | 8 ++++++-- 3 files changed, 17 insertions(+), 13 deletions(-) (limited to 'classes/feedparser.php') diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index 74be03d80..48e3aa567 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -43,9 +43,9 @@ class FeedItem_Atom extends FeedItem_Common { $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link); if ($base) - return rewrite_relative_url($base, $link->getAttribute("href")); + return rewrite_relative_url($base, trim($link->getAttribute("href"))); else - return $link->getAttribute("href"); + return trim($link->getAttribute("href")); } } @@ -55,7 +55,7 @@ class FeedItem_Atom extends FeedItem_Common { $title = $this->elem->getElementsByTagName("title")->item(0); if ($title) { - return $title->nodeValue; + return trim($title->nodeValue); } } @@ -106,13 +106,13 @@ class FeedItem_Atom extends FeedItem_Common { foreach ($categories as $cat) { if ($cat->hasAttribute("term")) - array_push($cats, $cat->getAttribute("term")); + array_push($cats, trim($cat->getAttribute("term"))); } $categories = $this->xpath->query("dc:subject", $this->elem); foreach ($categories as $cat) { - array_push($cats, $cat->nodeValue); + array_push($cats, trim($cat->nodeValue)); } return $cats; diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php index 28f4a388d..bf08a1dfe 100644 --- a/classes/feeditem/rss.php +++ b/classes/feeditem/rss.php @@ -33,20 +33,20 @@ class FeedItem_RSS extends FeedItem_Common { || $link->getAttribute("rel") == "alternate" || $link->getAttribute("rel") == "standout")) { - return $link->getAttribute("href"); + return trim($link->getAttribute("href")); } } $link = $this->elem->getElementsByTagName("guid")->item(0); if ($link && $link->hasAttributes() && $link->getAttribute("isPermaLink") == "true") { - return $link->nodeValue; + return trim($link->nodeValue); } $link = $this->elem->getElementsByTagName("link")->item(0); if ($link) { - return $link->nodeValue; + return trim($link->nodeValue); } } @@ -54,7 +54,7 @@ class FeedItem_RSS extends FeedItem_Common { $title = $this->elem->getElementsByTagName("title")->item(0); if ($title) { - return $title->nodeValue; + return trim($title->nodeValue); } } @@ -90,13 +90,13 @@ class FeedItem_RSS extends FeedItem_Common { $cats = array(); foreach ($categories as $cat) { - array_push($cats, $cat->nodeValue); + array_push($cats, trim($cat->nodeValue)); } $categories = $this->xpath->query("dc:subject", $this->elem); foreach ($categories as $cat) { - array_push($cats, $cat->nodeValue); + array_push($cats, trim($cat->nodeValue)); } return $cats; diff --git a/classes/feedparser.php b/classes/feedparser.php index 187875b5f..239fdb7a6 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -205,6 +205,10 @@ class FeedParser { break; } + + if ($this->title) $this->title = trim($this->title); + if ($this->link) $this->link = trim($this->link); + } else { if( !isset($this->error) ){ $this->error = "Unknown/unsupported feed type"; @@ -252,7 +256,7 @@ class FeedParser { foreach ($links as $link) { if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) { - array_push($rv, $link->getAttribute('href')); + array_push($rv, trim($link->getAttribute('href'))); } } break; @@ -261,7 +265,7 @@ class FeedParser { foreach ($links as $link) { if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) { - array_push($rv, $link->getAttribute('href')); + array_push($rv, trim($link->getAttribute('href'))); } } break; -- cgit v1.2.3-54-g00ecf