From 502e4b923e3805e7b2f172255e24a51a52a15c96 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Wed, 11 Jan 2023 16:43:27 +0100 Subject: don't process link if it's null don't process body of feed if it's null Co-authored-by: Sean Molenaar Signed-off-by: Benjamin Brahmer --- lib/Db/Feed.php | 8 +++++++- lib/Fetcher/FeedFetcher.php | 30 ++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/Db/Feed.php b/lib/Db/Feed.php index 3c371087b..5821466a5 100644 --- a/lib/Db/Feed.php +++ b/lib/Db/Feed.php @@ -326,13 +326,16 @@ class Feed extends Entity implements IAPI, \JsonSerializable 'basicAuthPassword' ]); + if (is_null($this->link)) { + return $serialized; + } + $url = parse_url($this->link, PHP_URL_HOST); // strip leading www. to avoid css class confusion if (strpos($url, 'www.') === 0) { $url = substr($url, 4); } - $serialized['cssClass'] = 'custom-' . str_replace('.', '-', $url); return $serialized; @@ -488,6 +491,9 @@ class Feed extends Entity implements IAPI, \JsonSerializable */ public function setLink(?string $link = null): Feed { + if (is_null($link)) { + return $this; + } $link = trim($link); if (strpos($link, 'http') === 0 && $this->link !== $link) { $this->link = $link; diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php index 86e0edd18..c79d40685 100755 --- a/lib/Fetcher/FeedFetcher.php +++ b/lib/Fetcher/FeedFetcher.php @@ -301,22 +301,24 @@ class FeedFetcher implements IFeedFetcher } // purification is done in the service layer - $body = mb_convert_encoding( - $body, - 'HTML-ENTITIES', - mb_detect_encoding($body) - ); - if (strpos($body, 'CDATA') !== false) { - libxml_use_internal_errors(true); - $data = simplexml_load_string( - "$body", - SimpleXMLElement::class, - LIBXML_NOCDATA + if (!is_null($body)) { + $body = mb_convert_encoding( + $body, + 'HTML-ENTITIES', + mb_detect_encoding($body) ); - if ($data !== false && libxml_get_last_error() === false) { - $body = (string) $data; + if (strpos($body, 'CDATA') !== false) { + libxml_use_internal_errors(true); + $data = simplexml_load_string( + "$body", + SimpleXMLElement::class, + LIBXML_NOCDATA + ); + if ($data !== false && libxml_get_last_error() === false) { + $body = (string) $data; + } + libxml_clear_errors(); } - libxml_clear_errors(); } $item->setBody($body); -- cgit v1.2.3