diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 14722587..0928fc18 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -62,6 +62,9 @@ jobs: - name: PHPStan run: composer run-script phpstan + - name: PHPStan compatibility PHP < 8.4 + run: composer run-script phpstan-php83 + # NPM tests - name: Uses Node.js diff --git a/composer.json b/composer.json index e1746f8a..41b072ad 100644 --- a/composer.json +++ b/composer.json @@ -68,6 +68,7 @@ "phpcs": "phpcs . -s", "phpcbf": "phpcbf . -p -s", "phpstan": "phpstan analyse .", + "phpstan-php83": "phpstan analyse -c phpstan-php83.neon .", "phpstan-third-party": "phpstan analyse -c phpstan-third-party.neon .", "test-image-proxy": "php tests/ImageProxyTest.php", "test": [ @@ -75,7 +76,8 @@ "@phtml-lint", "@test-image-proxy", "@phpcs", - "@phpstan" + "@phpstan", + "@phpstan-php83" ], "fix": [ "@phpcbf" diff --git a/phpstan-php83.neon b/phpstan-php83.neon new file mode 100644 index 00000000..31d29754 --- /dev/null +++ b/phpstan-php83.neon @@ -0,0 +1,36 @@ +# Compatibility PHP < 8.4, due to new class `Dom\` introduced in PHP 8.4+ +parameters: + phpVersion: + min: 80100 # PHP 8.1 + max: 80399 # PHP 8.3 + level: 9 # https://phpstan.org/user-guide/rule-levels + fileExtensions: + - php + - phtml + paths: + - ../FreshRSS + - . + excludePaths: + analyse: + - ../FreshRSS + analyseAndScan: + - .git/*? + - node_modules/*? + - symbolic/*? + - third-party/*? + - tmp/*? + - vendor/ + reportUnmatchedIgnoredErrors: false + treatPhpDocTypesAsCertain: false + dynamicConstantNames: + - TYPE_GIT + ignoreErrors: + # `Dom\` used by PHP 8.4+ + - + identifier: class.notFound + messages: + - '#^Class Dom\\\S+ not found\.$#' + - '#^Parameter \S+ of .+ has invalid type Dom\\\S+\.$#' + - '#^.+ has invalid return type Dom\\\S+\.$#' + - '#^Property \S+ has unknown class Dom\\\S+ as its type\.$#' + - '#^Call to method \S+ on an unknown class Dom\\\S+\.$#' diff --git a/phpstan.dist.neon b/phpstan.dist.neon index a7c0c4f6..38f3ecdf 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -1,6 +1,6 @@ parameters: phpVersion: - min: 80100 # PHP 8.1 + min: 80400 # PHP 8.4 (PHP 8.1+ covered by phpstan-php83.neon) max: 80599 # PHP 8.5 level: 10 # https://phpstan.org/user-guide/rule-levels fileExtensions: diff --git a/tests/ImageProxyTest.php b/tests/ImageProxyTest.php index ad07f6fa..f18286da 100644 --- a/tests/ImageProxyTest.php +++ b/tests/ImageProxyTest.php @@ -67,6 +67,7 @@ public function run(): void { $this->testHtmlDocumentsAndTagSoup(); $this->testImageAttributes(); $this->testVideoPosters(); + $this->testHtml5Parsing(); $this->testUriSchemes(); $this->testExcludedDomains(); } catch (FreshRSS_Context_Exception $e) { @@ -143,8 +144,8 @@ private function testImageAttributes(): void { $this->assertSame(3, count($images), 'All image elements must remain present'); $this->assertSame( - self::PROXY_URL . 'http://images.example/one%20caf%C3%A9.jpg', - $images[0]->getAttribute('src'), + self::PROXY_URL . 'http://images.example/one café.jpg', + rawurldecode($images[0]->getAttribute('src')), // The legacy parser of PHP < 8.4 percent-encodes URLs when serialising 'Unicode image URLs must be proxied', ); $this->assertSame( @@ -188,6 +189,19 @@ private function testVideoPosters(): void { $this->assertSame(false, $videos[1]->hasAttribute('poster'), 'Videos without poster must remain without poster'); } + /** @throws FreshRSS_Context_Exception */ + private function testHtml5Parsing(): void { + if (!class_exists('Dom\HTMLDocument')) { + return; // The HTML5 parser is only available in PHP 8.4+ + } + + $this->assertSame( + '
Body text
', + ImageProxyExtension::swapUris('Body text
'), + 'The element must not be returned, even with attributes', + ); + } + /** @throws FreshRSS_Context_Exception */ private function testUriSchemes(): void { $this->assertSame( diff --git a/xExtension-ImageProxy/README.md b/xExtension-ImageProxy/README.md index 2a7bbce3..b8019373 100644 --- a/xExtension-ImageProxy/README.md +++ b/xExtension-ImageProxy/README.md @@ -6,6 +6,7 @@ To use it, upload this entire directory to the FreshRSS `./extensions` directory ## Changelog +* 1.1.1 Use the standard HTML5 parser of PHP 8.4+ when available * 1.1.0 Add a list of domains that are not proxied * 1.0.4 Respect the feed option to hide enclosures * 1.0.3 Proxy the poster images of videos diff --git a/xExtension-ImageProxy/extension.php b/xExtension-ImageProxy/extension.php index d7d97fa6..6c139968 100644 --- a/xExtension-ImageProxy/extension.php +++ b/xExtension-ImageProxy/extension.php @@ -149,24 +149,16 @@ public static function getSrcSetUris(array $matches): string { } /** + * Proxies the images of a parsed HTML document: `src` and `srcset` of `