From 56ebffbf76d26609388b16a716a68c2ef26e9162 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Wed, 28 Apr 2021 20:52:50 +0200 Subject: [Backport] Prevent some of the favicon fetching errors Signed-off-by: Benjamin Brahmer --- CHANGELOG.md | 3 ++- composer.lock | 41 ++++++++++++++++----------------- lib/Fetcher/FeedFetcher.php | 24 ++++++++++++------- tests/integration/feeds.bats | 17 +++++++++++++- tests/integration/helpers/settings.bash | 3 ++- 5 files changed, 56 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24000988f..451743400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,9 +21,10 @@ The format is almost based on [Keep a Changelog](https://keepachangelog.com/en/1 ### Fixed - # Releases ## [15.4.1] - 2021-05-03 +### Known Issue +If you use a 32bit OS your will run into #1320 ### Fixed - content of atom feeds is missing (#1325) - Fix some of the favicon fetching errors (#1319) diff --git a/composer.lock b/composer.lock index 3fe2c4957..45fefca13 100644 --- a/composer.lock +++ b/composer.lock @@ -447,40 +447,39 @@ }, { "name": "doctrine/cache", - "version": "1.10.2", + "version": "1.11.0", "source": { "type": "git", "url": "https://github.com/doctrine/cache.git", - "reference": "13e3381b25847283a91948d04640543941309727" + "reference": "a9c1b59eba5a08ca2770a76eddb88922f504e8e0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/13e3381b25847283a91948d04640543941309727", - "reference": "13e3381b25847283a91948d04640543941309727", + "url": "https://api.github.com/repos/doctrine/cache/zipball/a9c1b59eba5a08ca2770a76eddb88922f504e8e0", + "reference": "a9c1b59eba5a08ca2770a76eddb88922f504e8e0", "shasum": "" }, "require": { "php": "~7.1 || ^8.0" }, "conflict": { - "doctrine/common": ">2.2,<2.4" + "doctrine/common": ">2.2,<2.4", + "psr/cache": ">=3" }, "require-dev": { "alcaeus/mongo-php-adapter": "^1.1", - "doctrine/coding-standard": "^6.0", + "cache/integration-tests": "dev-master", + "doctrine/coding-standard": "^8.0", "mongodb/mongodb": "^1.1", - "phpunit/phpunit": "^7.0", - "predis/predis": "~1.0" + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", + "predis/predis": "~1.0", + "psr/cache": "^1.0 || ^2.0", + "symfony/cache": "^4.4 || ^5.2" }, "suggest": { "alcaeus/mongo-php-adapter": "Required to use legacy MongoDB driver" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.9.x-dev" - } - }, "autoload": { "psr-4": { "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" @@ -527,7 +526,7 @@ ], "support": { "issues": "https://github.com/doctrine/cache/issues", - "source": "https://github.com/doctrine/cache/tree/1.10.x" + "source": "https://github.com/doctrine/cache/tree/1.11.0" }, "funding": [ { @@ -543,7 +542,7 @@ "type": "tidelift" } ], - "time": "2020-07-07T18:54:01+00:00" + "time": "2021-04-13T14:46:17+00:00" }, { "name": "doctrine/dbal", @@ -1590,16 +1589,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.5", + "version": "9.2.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1" + "reference": "f6293e1b30a2354e8428e004689671b83871edde" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f3e026641cc91909d421802dd3ac7827ebfd97e1", - "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f6293e1b30a2354e8428e004689671b83871edde", + "reference": "f6293e1b30a2354e8428e004689671b83871edde", "shasum": "" }, "require": { @@ -1655,7 +1654,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.5" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.6" }, "funding": [ { @@ -1663,7 +1662,7 @@ "type": "github" } ], - "time": "2020-11-28T06:44:49+00:00" + "time": "2021-03-28T07:26:59+00:00" }, { "name": "phpunit/php-file-iterator", diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php index f3d4e0f27..ef232eece 100755 --- a/lib/Fetcher/FeedFetcher.php +++ b/lib/Fetcher/FeedFetcher.php @@ -327,28 +327,36 @@ class FeedFetcher implements IFeedFetcher { $favicon = $feed->getLogo(); - // check if feed has a logo - if (is_null($favicon)) { - return $this->faviconFactory->get($url); + ini_set('user_agent', 'NextCloud-News/1.0'); + + $base_url = new Net_URL2($url); + $base_url->setPath(""); + $base_url = $base_url->getNormalizedURL(); + + // check if feed has a logo entry + if (is_null($favicon) || trim($favicon) === '') { + return $this->faviconFactory->get($base_url); } $favicon_path = join("/", [$this->ITempManager->getTempBaseDir(), basename($favicon)]); - copy( + + $downloaded = copy( $favicon, - $favicon_path + $favicon_path, + stream_context_create([ 'http' => [ 'ignore_errors' => true ] ]) ); - $is_image = substr(mime_content_type($favicon_path), 0, 5) === "image"; + $is_image = $downloaded && substr(mime_content_type($favicon_path), 0, 5) === "image"; // check if file is actually an image if (!$is_image) { - return $this->faviconFactory->get($url); + return $this->faviconFactory->get($base_url); } list($width, $height, $type, $attr) = getimagesize($favicon_path); // check if image is square else fall back to favicon if ($width !== $height) { - return $this->faviconFactory->get($url); + return $this->faviconFactory->get($base_url); } return $favicon; diff --git a/tests/integration/feeds.bats b/tests/integration/feeds.bats index 2701cbfa9..1e60b5552 100644 --- a/tests/integration/feeds.bats +++ b/tests/integration/feeds.bats @@ -34,9 +34,24 @@ teardown() { return $ret_status fi +} + +@test "[$TESTSUITE] Favicon" { + ./occ news:feed:add "$user" "$NC_FEED" --title "Something-${BATS_SUITE_TEST_NUMBER}" + ./occ news:feed:add "$user" "$HEISE_FEED" --title "Something-${BATS_SUITE_TEST_NUMBER}" + + run ./occ news:feed:list "$user" + [ "$status" -eq 0 ] + if ! echo "$output" | grep -F '"faviconLink": "https:\/\/nextcloud.com\/media\/screenshot-150x150.png"'; then ret_status=$? - echo "Favicon not found in list" + echo "Logo test failed" + return $ret_status + fi + + if ! echo "$output" | grep -F '"faviconLink": "https:\/\/www.heise.de\/favicon.ico"'; then + ret_status=$? + echo "Favicon test failed" return $ret_status fi } diff --git a/tests/integration/helpers/settings.bash b/tests/integration/helpers/settings.bash index 48b5a3726..4e758b609 100644 --- a/tests/integration/helpers/settings.bash +++ b/tests/integration/helpers/settings.bash @@ -1,2 +1,3 @@ user=admin -NC_FEED="https://nextcloud.com/blog/static-feed/" \ No newline at end of file +NC_FEED="https://nextcloud.com/blog/static-feed/" +HEISE_FEED="https://www.heise.de/rss/heise-atom.xml" \ No newline at end of file -- cgit v1.2.3