From 032d48ad7b180c80344a8fe64b2f9bfc81cef7b1 Mon Sep 17 00:00:00 2001 From: nextcloud486153 <78801830+nextcloud486153@users.noreply.github.com> Date: Mon, 18 Apr 2022 11:59:02 +0200 Subject: Fix malformed feeds (without GUIDs) stopping the update process (fixes #1738) Signed-off-by: nextcloud486153 <78801830+nextcloud486153@users.noreply.github.com> --- CHANGELOG.md | 1 + lib/Fetcher/FeedFetcher.php | 4 ++ tests/Unit/Fetcher/FeedFetcherTest.php | 2 +- tests/integration/feeds.bats | 11 +++++ tests/integration/feeds/no_guid_feed.xml | 78 ++++++++++++++++++++++++++++++++ tests/integration/helpers/settings.bash | 3 +- 6 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 tests/integration/feeds/no_guid_feed.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index a51c125d2..a055a197f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is mostly based on [Keep a Changelog](https://keepachangelog.com/en/1 ### Fixed - Fix import of items when feed does not exist (1742) +- Fix malformed feeds (without GUIDs) stopping the update process (#1738) # Releases ## [18.0.1-beta2] - 2022-03-22 diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php index 9e70b62ca..a6ddbacb5 100755 --- a/lib/Fetcher/FeedFetcher.php +++ b/lib/Fetcher/FeedFetcher.php @@ -18,6 +18,7 @@ use Favicon\Favicon; use FeedIo\Feed\ItemInterface; use FeedIo\FeedInterface; use FeedIo\FeedIo; +use FeedIo\Reader\ReadErrorException; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\ConnectException; @@ -233,6 +234,9 @@ class FeedFetcher implements IFeedFetcher $item = new Item(); $item->setUnread(true); $item->setUrl($parsedItem->getLink()); + if ($parsedItem->getPublicId() == null) { + throw new ReadErrorException("Malformed feed: item has no GUID"); + } $item->setGuid($parsedItem->getPublicId()); $item->setGuidHash(md5($item->getGuid())); diff --git a/tests/Unit/Fetcher/FeedFetcherTest.php b/tests/Unit/Fetcher/FeedFetcherTest.php index 32b03d3e4..42f518453 100644 --- a/tests/Unit/Fetcher/FeedFetcherTest.php +++ b/tests/Unit/Fetcher/FeedFetcherTest.php @@ -579,7 +579,7 @@ class FeedFetcherTest extends TestCase $this->item_mock->expects($this->exactly(2)) ->method('getTitle') ->will($this->returnValue($this->title)); - $this->item_mock->expects($this->exactly(1)) + $this->item_mock->expects($this->exactly(2)) ->method('getPublicId') ->will($this->returnValue($this->guid)); $this->item_mock->expects($this->exactly(1)) diff --git a/tests/integration/feeds.bats b/tests/integration/feeds.bats index 1e60b5552..5ad52dc30 100644 --- a/tests/integration/feeds.bats +++ b/tests/integration/feeds.bats @@ -22,6 +22,17 @@ teardown() { fi } +@test "[$TESTSUITE] Add feed without GUIDs" { + run ./occ news:feed:add "$user" "$NO_GUID_FEED" + [ "$status" -ne 0 ] + + if ! echo "$output" | grep "No parser can handle this stream"; then + ret_status=$? + echo "Malformed feed exception wasn't properly caught" + return $ret_status + fi +} + @test "[$TESTSUITE] List all" { ./occ news:feed:add "$user" "$NC_FEED" --title "Something-${BATS_SUITE_TEST_NUMBER}" diff --git a/tests/integration/feeds/no_guid_feed.xml b/tests/integration/feeds/no_guid_feed.xml new file mode 100644 index 000000000..e27a1b07b --- /dev/null +++ b/tests/integration/feeds/no_guid_feed.xml @@ -0,0 +1,78 @@ + + + + RSS Builder by B!Soft + Joshua Wright Dot Net + http://www.joshuawright.net + This is a feed of the latest comic masterpiece from joshuawright.net + en + joshua.wright@live.com.au (Josh Wright) + joshua.wright@live.com.au (Josh Wright) + 2016 JoshuaWright + + Slack Wyrm 911 - Feeling better + Wed, 13 Apr 2022 09:07:01 +0100 + https://joshuawright.net/slack-wyrm-911.html + + + + Slack Wyrm 910 - Cake trip + Mon, 11 Apr 2022 08:52:54 +0100 + https://joshuawright.net/slack-wyrm-910.html + + + + Slack Wyrm 909 - Cake time + Fri, 8 Apr 2022 09:29:32 +0100 + + + + Slack Wyrm 908 - Dragons Lair + Wed, 6 Apr 2022 09:00:13 +0100 + https://joshuawright.net/slack-wyrm-908.html + + + + Slack Wyrm 907 - Ten feet tall + Mon, 4 Apr 2022 15:12:51 +0100 + https://joshuawright.net/slack-wyrm-907.html + + + + Slack Wyrm 906 - True self + Fri, 1 Apr 2022 09:28:06 +1100 + https://joshuawright.net/slack-wyrm-906.html + + + + Slack Wyrm 905 - Drink up + Wed, 30 Mar 2022 11:07:49 +1100 + https://joshuawright.net/slack-wyrm-905.html + + + + Slack Wyrm 904 - Marvellous medicine + Mon, 28 Mar 2022 09:02:44 +1100 + https://joshuawright.net/slack-wyrm-904.html + + + + Slack Wyrm 903 - Golden still + Fri, 25 Mar 2022 09:48:06 +1100 + https://joshuawright.net/slack-wyrm-903.html + + + + Slack Wyrm 902 - Janet the genius + Wed, 23 Mar 2022 09:30:47 +1100 + https://joshuawright.net/slack-wyrm-902.html + + + + Slack Wyrm 901 - Bye bye Bucky + Mon, 21 Mar 2022 09:01:36 +1100 + https://joshuawright.net/slack-wyrm-901.html + + + + \ No newline at end of file diff --git a/tests/integration/helpers/settings.bash b/tests/integration/helpers/settings.bash index 4e758b609..bf58a601a 100644 --- a/tests/integration/helpers/settings.bash +++ b/tests/integration/helpers/settings.bash @@ -1,3 +1,4 @@ user=admin NC_FEED="https://nextcloud.com/blog/static-feed/" -HEISE_FEED="https://www.heise.de/rss/heise-atom.xml" \ No newline at end of file +HEISE_FEED="https://www.heise.de/rss/heise-atom.xml" +NO_GUID_FEED="https://raw.githubusercontent.com/nextcloud/news/master/tests/integration/feeds/no_guid_feed.xml" -- cgit v1.2.3