From ae6954f0e4491c2d2223a78dab262349d72ef72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Sat, 16 Oct 2021 17:58:59 +0200 Subject: [PATCH] Feed: Add edge conditions. --- src/Feed.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Feed.php b/src/Feed.php index 3bb7fef..1a61eed 100644 --- a/src/Feed.php +++ b/src/Feed.php @@ -113,13 +113,20 @@ private function downloadRawFeed(string $url): string if ($haystack === false) { trigger_error('Feed URL "' . $url . '" is broken.'); } + $haystack = trim((string) $haystack); + if ($haystack === '') { + throw new \RuntimeException('Feed response for URL "' . $url . '" is empty.'); + } - return (string) $haystack; + return $haystack; } private function writeCache(string $url, string $content, ?string $expiration = null): void { + if ($content === '') { // ignore empty content + return; + } $this->cache->save($url, $content, [ Cache::EXPIRATION => $expiration ?? $this->expirationTime, ]);