|
@@ -39,6 +39,28 @@ final class httpUtilTest extends \PHPUnit\Framework\TestCase {
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ #[DataProvider('provideUtf8Html')]
|
|
|
|
|
+ public function test_enforceHtmlBase_keepsUtf8InScripts(string $html): void {
|
|
|
|
|
+ $enforceHtmlBase = new ReflectionMethod(FreshRSS_http_Util::class, 'enforceHtmlBase');
|
|
|
|
|
+ $result = $enforceHtmlBase->invoke(null, $html, 'https://example.net/page');
|
|
|
|
|
+ self::assertIsString($result);
|
|
|
|
|
+ self::assertStringContainsString('<base href="https://example.net/page">', $result);
|
|
|
|
|
+ self::assertStringContainsString('<script type="application/json">{"title":"Café’s menu — 日本"}</script>', $result);
|
|
|
|
|
+ if (str_starts_with($html, "\xEF\xBB\xBF")) {
|
|
|
|
|
+ self::assertStringStartsWith("\xEF\xBB\xBF", $result);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** @return Traversable<string,array{string}> */
|
|
|
|
|
+ public static function provideUtf8Html(): Traversable {
|
|
|
|
|
+ $head = '<html><head><title>T</title></head>';
|
|
|
|
|
+ $body = '<body><p>Café’s menu — 日本</p><script type="application/json">{"title":"Café’s menu — 日本"}</script></body></html>';
|
|
|
|
|
+ yield 'meta charset' => ['<!DOCTYPE html><html><head><meta charset="utf-8"><title>T</title></head>' . $body];
|
|
|
|
|
+ yield 'byte order mark' => ["\xEF\xBB\xBF" . '<!DOCTYPE html>' . $head . $body];
|
|
|
|
|
+ yield 'byte order mark, late <html>' => ["\xEF\xBB\xBF" . '<!DOCTYPE html>' . str_repeat('<!-- padding -->', 40) . $head . $body];
|
|
|
|
|
+ yield 'meta http-equiv' => ['<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>T</title></head>' . $body];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
#[DataProvider('provideCidrRanges')]
|
|
#[DataProvider('provideCidrRanges')]
|
|
|
public function test_checkCIDR(string $ip, string $range, bool $expected): void {
|
|
public function test_checkCIDR(string $ip, string $range, bool $expected): void {
|
|
|
$checkCIDR = new ReflectionMethod(FreshRSS_http_Util::class, 'checkCIDR');
|
|
$checkCIDR = new ReflectionMethod(FreshRSS_http_Util::class, 'checkCIDR');
|