From d7e1e5ac5a1dfcc9643e420ab6bef04a3c4d943b Mon Sep 17 00:00:00 2001 From: NopeCharon <115794254+NopeCharon@users.noreply.github.com> Date: Thu, 12 Nov 2026 13:37:32 +0530 Subject: [PATCH 1/2] [xExtension-ImageProxy] Use the HTML5 parser of PHP 8.4+ when available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The extension parsed the article content with `DOMDocument::loadHTML()`, which relies on the HTML 4 parser of libxml2 and alters modern markup when the content is serialised back: * void elements unknown to HTML 4, such as ``, are turned into containers that swallow the following elements, e.g. the `` of a `` ends up inside `…`; * loose text at the start of the content is wrapped in a `

`; * a `` element with attributes is returned with the content, because only a bare `` tag was stripped from the output. On PHP 8.4+, parse the content with `Dom\HTMLDocument::createFromString()`, which implements the standard HTML5 parsing algorithm, and return the `innerHTML` of the body, so no tag needs to be stripped anymore. The content is always UTF-8 in FreshRSS, which is now passed as the encoding instead of converting every non-ASCII character to a numeric entity. The legacy `DOMDocument` code is kept for PHP 8.1 to 8.3. The proxying of `` and `

after

' + ); + $this->assertSame( + '' + . '' + . '

after

', + $picture, + 'Void elements such as must not swallow the following elements', + ); + + $this->assertSame( + 'Loose text &
line', + ImageProxyExtension::swapUris('Loose text &
line'), + 'Loose text must not be wrapped in a paragraph', + ); + + $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/tests/stubs/php84-dom.php b/tests/stubs/php84-dom.php new file mode 100644 index 00000000..970bd6c4 --- /dev/null +++ b/tests/stubs/php84-dom.php @@ -0,0 +1,36 @@ + + */ +class HTMLCollection implements \IteratorAggregate, \Countable { + public function count(): int {} + /** @return \Iterator */ + public function getIterator(): \Iterator {} + public function item(int $index): ?Element {} +} + +abstract class Document extends Node { + public ?HTMLElement $body; + public function getElementsByTagName(string $qualifiedName): HTMLCollection {} +} + +final class HTMLDocument extends Document { + public static function createFromString(string $source, int $options = 0, ?string $overrideEncoding = null): HTMLDocument {} +} diff --git a/xExtension-ImageProxy/README.md b/xExtension-ImageProxy/README.md index 81ae273e..c6791efa 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.0.5 Use the standard HTML5 parser of PHP 8.4+ when available * 1.0.4 Respect the feed option to hide enclosures * 1.0.3 Proxy the poster images of videos * 1.0.1 Replace deprecated HTML entity conversion on PHP 8.2+ diff --git a/xExtension-ImageProxy/extension.php b/xExtension-ImageProxy/extension.php index 4b35a07f..0f33a03a 100644 --- a/xExtension-ImageProxy/extension.php +++ b/xExtension-ImageProxy/extension.php @@ -120,24 +120,16 @@ public static function getSrcSetUris(array $matches): string { } /** + * Proxies the images of a parsed HTML document: `src` and `srcset` of `` and `poster` of `