A free, self-hostable news aggregator…
Better XPath failure (#5317)
Alexandre Alapetite5579dc88abee
diff --git a/app/Models/Feed.php b/app/Models/Feed.phpindex 0d7c35739..e96323d04 100644--- a/app/Models/Feed.php+++ b/app/Models/Feed.php@@ -641,16 +641,19 @@ class FreshRSS_Feed extends Minz_Model {$doc = new DOMDocument();$doc->recover = true;$doc->strictErrorChecking = false;+ $ok = false;switch ($this->kind()) {case FreshRSS_Feed::KIND_HTML_XPATH:- $doc->loadHTML($html, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING);+ $ok = $doc->loadHTML($html, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING) !== false;break;case FreshRSS_Feed::KIND_XML_XPATH:- $doc->loadXML($html, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING);+ $ok = $doc->loadXML($html, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING) !== false;break;- default:- return null;+ }++ if (!$ok) {+ return null;}$xpath = new DOMXPath($doc);@@ -658,7 +661,7 @@ class FreshRSS_Feed extends Minz_Model {htmlspecialchars(@$xpath->evaluate('normalize-space(' . $xPathFeedTitle . ')'), ENT_COMPAT, 'UTF-8');$view->rss_base = htmlspecialchars(trim($xpath->evaluate('normalize-space(//base/@href)')), ENT_COMPAT, 'UTF-8');$nodes = $xpath->query($xPathItem);- if (empty($nodes)) {+ if ($nodes === false || $nodes->length === 0) {return null;}diff --git a/lib/lib_rss.php b/lib/lib_rss.phpindex de9ca421e..fcdd8d787 100644--- a/lib/lib_rss.php+++ b/lib/lib_rss.php@@ -485,8 +485,7 @@ function httpGet(string $url, string $cachePath, string $type = 'html', array $aMinz_Log::warning('Error fetching content: HTTP code ' . $c_status . ': ' . $c_error . ' ' . $url);$body = '';// TODO: Implement HTTP 410 Gone- }- if (!is_string($body)) {+ } elseif (!is_string($body) || strlen($body) === 0) {$body = '';} else {$body = enforceHttpEncoding($body, $c_content_type);