*/
public static function provideMaliciousHtml(): Traversable {
yield 'script tag' => ['Hello', '">click', 'href="data:'];
yield 'data:text/html URL in iframe' => ['', 'src="data:'];
yield 'data:text/html URL in image' => ['', 'src="data:'];
yield 'data:image URL in link' => ['click', 'href="data:'];
}
public static function test_sanitizeHTML_whenSafeHtml_keepsAllowedTags(): void {
$result = FreshRSS_SimplePieCustom::sanitizeHTML('
Hello world
'); self::assertSame('Hello world
', $result); } public static function test_sanitizeHTML_whenUnsafeAttributeIsRemoved_keepsAllowedTag(): void { self::assertSame('HelloHello world
', maxLength: 0)); self::assertSame('', FreshRSS_SimplePieCustom::sanitizeHTML('Hello world
', maxLength: -1)); } public static function test_sanitizeHTML_whenResultFitsWithinMaxLength_isUnaffected(): void { $result = FreshRSS_SimplePieCustom::sanitizeHTML('Hello world
', maxLength: 100); self::assertSame('Hello world
', $result); } public static function test_sanitizeHTML_whenUnsafePrefixExceedsMaxLength_keepsSafeText(): void { self::assertSame('text', FreshRSS_SimplePieCustom::sanitizeHTML('text', maxLength: 5)); } /** * Sanitizing can grow a truncated fragment (e.g. `
He` gets sanitized into `
He
`) */ #[DataProvider('provideMaxLengthInputs')] public static function test_sanitizeHTML_whenMaxLengthForcesReSanitizing_terminatesWithinBound(string $input, int $maxLength): void { $result = FreshRSS_SimplePieCustom::sanitizeHTML($input, maxLength: $maxLength); self::assertLessThanOrEqual($maxLength, strlen($result)); } /** @return TraversableHello world
', 5]; yield 'repeated short tags' => [str_repeat('x ', 50), 20]; yield 'single-character budget' => ['Hello world
', 1]; } #[DataProvider('provideIncompleteTagsOrEntities')] public static function test_sanitizeHTML_Cases(string $input, int $maxLength, string $expected): void { $result = FreshRSS_SimplePieCustom::sanitizeHTML($input, maxLength: $maxLength); self::assertLessThanOrEqual($maxLength, strlen($result)); self::assertSame(trim($expected), trim($result)); } /** @return Traversable