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.
48 lines
2.2 KiB
PHP
48 lines
2.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\Attributes\PreserveGlobalState;
|
|
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
|
|
|
|
#[RunTestsInSeparateProcesses]
|
|
#[PreserveGlobalState(false)]
|
|
final class streamFooterTest extends \PHPUnit\Framework\TestCase {
|
|
|
|
/** @return Traversable<string,array{array<string,string>,int,string}> */
|
|
public static function providePaginationStates(): Traversable {
|
|
yield 'automatic first page' => [[], 2, '0'];
|
|
yield 'explicit unread first page' => [['state' => '2'], 2, '2'];
|
|
yield 'explicit favourite first page' => [['state' => '4'], 4, '4'];
|
|
yield 'automatic unread next page' => [['state' => '2', 'stateForRedirect' => '0'], 2, '0'];
|
|
yield 'automatic all next page' => [['state' => '3', 'stateForRedirect' => '0'], 3, '0'];
|
|
yield 'explicit favourite next page' => [['state' => '4', 'stateForRedirect' => '4'], 4, '4'];
|
|
}
|
|
|
|
/** @param array<string,string> $request */
|
|
#[DataProvider('providePaginationStates')]
|
|
public function testPaginationKeepsTheRequestedState(array $request, int $resolvedState, string $requestedState): void {
|
|
FreshRSS_Context::initSystem();
|
|
Minz_Translate::init('en');
|
|
FreshRSS_Context::$state = $resolvedState;
|
|
FreshRSS_Context::$continuation_id = '123';
|
|
FreshRSS_Context::$search = new FreshRSS_BooleanSearch('needle');
|
|
Minz_Request::_params($request + ['search' => 'needle']);
|
|
|
|
$view = new FreshRSS_View();
|
|
$view->_path('helpers/stream-footer.phtml');
|
|
// Fragment of a page, so prefix with `<!DOCTYPE html>`
|
|
$doc = Dom\HTMLDocument::createFromString('<!DOCTYPE html>' . $view->renderToString(), Dom\HTML_NO_DEFAULT_NS);
|
|
$button = $doc->getElementById('load_more');
|
|
self::assertInstanceOf(Dom\Element::class, $button);
|
|
$query = parse_url($button->getAttribute('formaction') ?? '', PHP_URL_QUERY);
|
|
self::assertIsString($query);
|
|
parse_str($query, $params);
|
|
self::assertSame((string)$resolvedState, $params['state'] ?? null);
|
|
self::assertSame($requestedState, $params['stateForRedirect'] ?? null);
|
|
self::assertSame('needle', $params['search'] ?? null);
|
|
self::assertSame('123', $params['cid'] ?? null);
|
|
self::assertSame('1', $params['ajax'] ?? null);
|
|
}
|
|
}
|