mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-12-02 13:32:43 -05:00
Currently, SimplePie uses legacy DOMDocument parsing, which outputs potentially problematic HTML, not correctly sanitised.
This breaks the assumption that one can use something like `<div><!-- some HTML sanitized from SimplePie --></div>`.
```
--- Expected
+++ Actual
@@ @@
'<ul>
- <li><div></div></li>
+ <li><div>
<li>Item</li>
-</ul>'
+</div></li></ul>'
```
When shown in a compliant Web browser, several tags will be wrongly closed, breaking the layout of the client.
This PR patches SimplePie to use the modern parser and code syntax, while maintaining a best-effort polyfill for legacy PHP versions < 8.4.
Depends on:
SimplePie: Upgrade to PHPStan 2
* https://github.com/FreshRSS/simplepie/pull/97
* https://github.com/simplepie/simplepie/pull/939
* https://github.com/simplepie/simplepie/pull/1019
SimplePie: Use PHP 8.4+ \Dom classes and functions
* https://github.com/FreshRSS/simplepie/pull/98
* https://github.com/simplepie/simplepie/issues/1021
SimplePie: Add unit test for HTML5 sanitizing compliance
* https://github.com/simplepie/simplepie/pull/1022
SimplePie: Remove obsolete xml_is_sane and XMLReader fallback
* https://github.com/simplepie/simplepie/pull/1023
CssXPath: Add support for case insensitivity
* https://github.com/phpgt/CssXPath/pull/256
fix https://github.com/FreshRSS/FreshRSS/issues/5201
fix https://github.com/FreshRSS/FreshRSS/issues/6830
fix https://github.com/FreshRSS/FreshRSS/issues/6831
~5% faster for HTML sanitising.
Remove SimpleXML. Remove XMLReader.
34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
final class CssXPathTest extends \PHPUnit\Framework\TestCase
|
|
{
|
|
public static function testCssXPathTranslatorClassExists(): void {
|
|
self::assertTrue(class_exists('GT\\CssXPath\\Translator'));
|
|
}
|
|
|
|
/**
|
|
* Test case-insensitive attribute flag, e.g. `link[href][rel~="icon" i]`
|
|
*/
|
|
public static function testCssXPathAttributeCaseFlag(): void {
|
|
$doc = \Dom\HTMLDocument::createFromString(<<<'HTML'
|
|
<!DOCTYPE html>
|
|
<html><body>
|
|
<link rel="ICON" href="a.ico" />
|
|
<link rel="shortcut icon" href="b.ico" />
|
|
<link rel="alternate" href="c.xml" />
|
|
</body></html>
|
|
HTML, Dom\HTML_NO_DEFAULT_NS);
|
|
$xpath = new \Dom\XPath($doc);
|
|
|
|
$links = $xpath->query((string)new \GT\CssXPath\Translator('link[href][rel~="icon" i]', './/'));
|
|
self::assertSame(2, $links->length);
|
|
$link0 = $links->item(0);
|
|
$link1 = $links->item(1);
|
|
self::assertInstanceOf(Dom\Element::class, $link0);
|
|
self::assertInstanceOf(Dom\Element::class, $link1);
|
|
self::assertSame('a.ico', $link0->getAttribute('href'));
|
|
self::assertSame('b.ico', $link1->getAttribute('href'));
|
|
}
|
|
}
|