From 6dfc4ad844d57ba4289df175d325f058c12025ef Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Wed, 28 Apr 2021 20:52:50 +0200 Subject: Prevent some of the favicon fetching errors change user agent for fetching the feeds log to 'NextCloud-News/1.0' check if logo in feed is just an empty string remove path of url before searching for a favicon check if file was actually downloaded Ignore http errors when fetching favicons Add feed to integration tests that doesn't have a logo Co-authored-by: Alec Kojaev Signed-off-by: Benjamin Brahmer --- CHANGELOG.md | 3 +- composer.lock | 149 ++++++++++++++++++++------------ lib/Fetcher/FeedFetcher.php | 24 +++-- tests/integration/feeds.bats | 17 +++- tests/integration/helpers/settings.bash | 3 +- 5 files changed, 130 insertions(+), 66 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3a07dc32..81f8387b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,8 @@ The format is almost based on [Keep a Changelog](https://keepachangelog.com/en/1 ### Changed ### Fixed -- content of atom feeds is missing +- content of atom feeds is missing (#1325) +- Fix some of the favicon fetching errors (#1319) # Releases ## [15.4.0] - 2021-04-26 diff --git a/composer.lock b/composer.lock index 2573dff0e..45fefca13 100644 --- a/composer.lock +++ b/composer.lock @@ -123,16 +123,16 @@ }, { "name": "debril/feed-io", - "version": "v4.9.3", + "version": "v4.9.6", "source": { "type": "git", "url": "https://github.com/alexdebril/feed-io.git", - "reference": "6f15c66b4087d41055f92bda9b499305e4ae97ca" + "reference": "810dfaae9fb89eb6df559b45ccf2db6c7e5a14f3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/alexdebril/feed-io/zipball/6f15c66b4087d41055f92bda9b499305e4ae97ca", - "reference": "6f15c66b4087d41055f92bda9b499305e4ae97ca", + "url": "https://api.github.com/repos/alexdebril/feed-io/zipball/810dfaae9fb89eb6df559b45ccf2db6c7e5a14f3", + "reference": "810dfaae9fb89eb6df559b45ccf2db6c7e5a14f3", "shasum": "" }, "require": { @@ -184,7 +184,7 @@ ], "support": { "issues": "https://github.com/alexdebril/feed-io/issues", - "source": "https://github.com/alexdebril/feed-io/tree/v4.9.3" + "source": "https://github.com/alexdebril/feed-io/tree/v4.9.6" }, "funding": [ { @@ -192,7 +192,7 @@ "type": "github" } ], - "time": "2021-03-12T21:57:53+00:00" + "time": "2021-04-20T20:30:38+00:00" }, { "name": "ezyang/htmlpurifier", @@ -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,37 +542,39 @@ "type": "tidelift" } ], - "time": "2020-07-07T18:54:01+00:00" + "time": "2021-04-13T14:46:17+00:00" }, { "name": "doctrine/dbal", - "version": "3.0.0", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "ee6d1260d5cc20ec506455a585945d7bdb98662c" + "reference": "5ba62e7e40df119424866064faf2cef66cb5232a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/ee6d1260d5cc20ec506455a585945d7bdb98662c", - "reference": "ee6d1260d5cc20ec506455a585945d7bdb98662c", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/5ba62e7e40df119424866064faf2cef66cb5232a", + "reference": "5ba62e7e40df119424866064faf2cef66cb5232a", "shasum": "" }, "require": { "composer/package-versions-deprecated": "^1.11.99", "doctrine/cache": "^1.0", + "doctrine/deprecations": "^0.5.3", "doctrine/event-manager": "^1.0", "php": "^7.3 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^8.1", - "jetbrains/phpstorm-stubs": "^2019.1", - "phpstan/phpstan": "^0.12.40", + "doctrine/coding-standard": "8.2.0", + "jetbrains/phpstorm-stubs": "2020.2", + "phpstan/phpstan": "0.12.81", "phpstan/phpstan-strict-rules": "^0.12.2", - "phpunit/phpunit": "^9.4", - "psalm/plugin-phpunit": "^0.10.0", + "phpunit/phpunit": "9.5.0", + "psalm/plugin-phpunit": "0.13.0", + "squizlabs/php_codesniffer": "3.6.0", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", - "vimeo/psalm": "^3.17.2" + "vimeo/psalm": "4.6.4" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." @@ -582,11 +583,6 @@ "bin/doctrine-dbal" ], "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.0.x-dev" - } - }, "autoload": { "psr-4": { "Doctrine\\DBAL\\": "src" @@ -638,7 +634,7 @@ ], "support": { "issues": "https://github.com/doctrine/dbal/issues", - "source": "https://github.com/doctrine/dbal/tree/3.0.0" + "source": "https://github.com/doctrine/dbal/tree/3.1.0" }, "funding": [ { @@ -654,7 +650,50 @@ "type": "tidelift" } ], - "time": "2020-11-15T18:20:41+00:00" + "time": "2021-04-19T17:51:23+00:00" + }, + { + "name": "doctrine/deprecations", + "version": "v0.5.3", + "source": { + "type": "git", + "url": "https://github.com/doctrine/deprecations.git", + "reference": "9504165960a1f83cc1480e2be1dd0a0478561314" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/9504165960a1f83cc1480e2be1dd0a0478561314", + "reference": "9504165960a1f83cc1480e2be1dd0a0478561314", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0|^7.0|^8.0", + "phpunit/phpunit": "^7.0|^8.0|^9.0", + "psr/log": "^1.0" + }, + "suggest": { + "psr/log": "Allows logging deprecations via PSR-3 logger implementation" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.", + "homepage": "https://www.doctrine-project.org/", + "support": { + "issues": "https://github.com/doctrine/deprecations/issues", + "source": "https://github.com/doctrine/deprecations/tree/v0.5.3" + }, + "time": "2021-03-21T12:59:47+00:00" }, { "name": "doctrine/event-manager", @@ -1316,16 +1355,16 @@ }, { "name": "phpstan/phpstan", - "version": "0.12.83", + "version": "0.12.85", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "4a967cec6efb46b500dd6d768657336a3ffe699f" + "reference": "20e6333c0067875ad7697cd8acdf245c6ef69d03" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/4a967cec6efb46b500dd6d768657336a3ffe699f", - "reference": "4a967cec6efb46b500dd6d768657336a3ffe699f", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/20e6333c0067875ad7697cd8acdf245c6ef69d03", + "reference": "20e6333c0067875ad7697cd8acdf245c6ef69d03", "shasum": "" }, "require": { @@ -1356,7 +1395,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/0.12.83" + "source": "https://github.com/phpstan/phpstan/tree/0.12.85" }, "funding": [ { @@ -1372,7 +1411,7 @@ "type": "tidelift" } ], - "time": "2021-04-03T15:35:45+00:00" + "time": "2021-04-27T14:13:16+00:00" }, { "name": "phpstan/phpstan-doctrine", @@ -1550,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": { @@ -1615,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": [ { @@ -1623,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", @@ -2935,16 +2974,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.5.8", + "version": "3.6.0", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "9d583721a7157ee997f235f327de038e7ea6dac4" + "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/9d583721a7157ee997f235f327de038e7ea6dac4", - "reference": "9d583721a7157ee997f235f327de038e7ea6dac4", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ffced0d2c8fa8e6cdc4d695a743271fab6c38625", + "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625", "shasum": "" }, "require": { @@ -2987,7 +3026,7 @@ "source": "https://github.com/squizlabs/PHP_CodeSniffer", "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" }, - "time": "2020-10-23T02:01:07+00:00" + "time": "2021-04-09T00:54:41+00:00" }, { "name": "symfony/polyfill-ctype", diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php index 134abb264..a7c4192e2 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