From 5e1082d7555a01df454afa8f473192dd703e3398 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 27 Jun 2025 15:15:46 +0200 Subject: [PATCH 1/4] Extract normalize entities tests to data provider and expand --- tests/phpunit/tests/kses.php | 77 +++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 10 deletions(-) diff --git a/tests/phpunit/tests/kses.php b/tests/phpunit/tests/kses.php index 256a3866ec17d..e47a9587baf75 100644 --- a/tests/phpunit/tests/kses.php +++ b/tests/phpunit/tests/kses.php @@ -550,19 +550,76 @@ public function test_hyphenated_tag() { $this->assertSame( $expect_valid_content, wp_kses( $content, $custom_tags ) ); } + /** + * Data provider. + */ + public static function data_html_entities(): array { + return array( + /** + * These examples are from the wp_kses_normalize_entities function description. + */ + 'AT&T' => array( 'AT&T', 'AT&T' ), + ':' => array( ':', ':' ), + '&#XYZZY;' => array( '&#XYZZY;', '&#XYZZY;' ), + + 'Named entity: &' => array( '♠', '♠' ), + 'Named entity: &' => array( '♠', '♠' ), + 'Named entity: ♠' => array( '♠', '♠' ), + 'Named entity: ¹' => array( '¹', '¹' ), + 'Named entity: ²' => array( '²', '²' ), + 'Named entity: ³' => array( '³', '³' ), + 'Named entity: ¼' => array( '¼', '¼' ), + 'Named entity: ½' => array( '½', '½' ), + 'Named entity: ¾' => array( '¾', '¾' ), + 'Named entity: ∴' => array( '∴', '∴' ), + + 'Numeric entity ( )' => array( ' ', ' ' ), + 'Numeric entity " (")' => array( '"', '"' ), + 'Numeric entity " (")' => array( '"', '"' ), + 'Numeric entity & (&)' => array( '&', '&' ), + "Numeric entity ' (')" => array( ''', ''' ), + 'Numeric entity 😍 (😍)' => array( '😍', '😍' ), + 'Numeric entity 😍 (😍)' => array( '😍', '😍' ), + + 'Hex entity ( )' => array( ' ', ' ' ), + 'Hex entity " (")' => array( '"', '"' ), + 'Hex entity " (")' => array( '"', '"' ), + 'Hex entity & (&)' => array( '&', '&' ), + "Hex entity ' (')" => array( ''', ''' ), + 'Hex entity 😍 (😍)' => array( '😍', '😍' ), + 'Hex entity 😍 (😍)' => array( '😍', '😍' ), + + 'HEX ENTITY " (")' => array( '"', '"' ), + 'HEX ENTITY & (&)' => array( '&', '&' ), + "HEX ENTITY ' (')" => array( ''', ''' ), + 'HEX ENTITY 😍 (😍)' => array( '😍', '😍' ), + + 'Encoded named entity &' => array( '&', '&' ), + 'Encoded named entity &' => array( '&', '&' ), + 'Encoded named entity &' => array( '&', '&' ), + 'Encoded numeric entity '' => array( ''', ''' ), + 'Encoded numeric entity '' => array( ''', ''' ), + 'Encoded numeric entity '' => array( ''', ''' ), + 'Encoded hex entity '' => array( ''', ''' ), + 'Encoded hex entity '' => array( ''', ''' ), + 'Encoded hex entity '' => array( ''', ''' ), + + /* + * The codepoint value here is outside of the valid unicode range whose + * maximum is 0x10FFFF or 1114111. + */ + 'Invalid numeric unicode �' => array( '�', '�' ), + 'Invalid hex unicode �' => array( '�', '�' ), + ); + } + /** * @ticket 26290 + * + * @dataProvider data_html_entities */ - public function test_wp_kses_normalize_entities() { - $this->assertSame( '♠', wp_kses_normalize_entities( '♠' ) ); - - $this->assertSame( '¹', wp_kses_normalize_entities( '¹' ) ); - $this->assertSame( '²', wp_kses_normalize_entities( '²' ) ); - $this->assertSame( '³', wp_kses_normalize_entities( '³' ) ); - $this->assertSame( '¼', wp_kses_normalize_entities( '¼' ) ); - $this->assertSame( '½', wp_kses_normalize_entities( '½' ) ); - $this->assertSame( '¾', wp_kses_normalize_entities( '¾' ) ); - $this->assertSame( '∴', wp_kses_normalize_entities( '∴' ) ); + public function test_wp_kses_normalize_entities( string $input, string $expected ) { + $this->assertSame( $expected, wp_kses_normalize_entities( $input ) ); } /** From 292346e261a47cb8bba38bfbe886d9453992e647 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 27 Jun 2025 15:25:00 +0200 Subject: [PATCH 2/4] Remove failing test cases --- tests/phpunit/tests/kses.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/phpunit/tests/kses.php b/tests/phpunit/tests/kses.php index e47a9587baf75..af140f4bc2f18 100644 --- a/tests/phpunit/tests/kses.php +++ b/tests/phpunit/tests/kses.php @@ -597,12 +597,6 @@ public static function data_html_entities(): array { 'Encoded named entity &' => array( '&', '&' ), 'Encoded named entity &' => array( '&', '&' ), 'Encoded named entity &' => array( '&', '&' ), - 'Encoded numeric entity '' => array( ''', ''' ), - 'Encoded numeric entity '' => array( ''', ''' ), - 'Encoded numeric entity '' => array( ''', ''' ), - 'Encoded hex entity '' => array( ''', ''' ), - 'Encoded hex entity '' => array( ''', ''' ), - 'Encoded hex entity '' => array( ''', ''' ), /* * The codepoint value here is outside of the valid unicode range whose From 8b0cae05eb4d5041dba5efae0263e5729fd354d0 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 27 Jun 2025 18:57:24 +0200 Subject: [PATCH 3/4] Use more appropriate name for data provider function --- tests/phpunit/tests/kses.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/kses.php b/tests/phpunit/tests/kses.php index af140f4bc2f18..fd66aa39ce750 100644 --- a/tests/phpunit/tests/kses.php +++ b/tests/phpunit/tests/kses.php @@ -553,7 +553,7 @@ public function test_hyphenated_tag() { /** * Data provider. */ - public static function data_html_entities(): array { + public static function data_normalize_entities(): array { return array( /** * These examples are from the wp_kses_normalize_entities function description. @@ -610,7 +610,7 @@ public static function data_html_entities(): array { /** * @ticket 26290 * - * @dataProvider data_html_entities + * @dataProvider data_normalize_entities */ public function test_wp_kses_normalize_entities( string $input, string $expected ) { $this->assertSame( $expected, wp_kses_normalize_entities( $input ) ); From e99472cf082af18f73563b889f201ce6782d8ad2 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 27 Jun 2025 19:04:25 +0200 Subject: [PATCH 4/4] Improve language in test cases --- tests/phpunit/tests/kses.php | 72 ++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/phpunit/tests/kses.php b/tests/phpunit/tests/kses.php index fd66aa39ce750..61baf0d0a1863 100644 --- a/tests/phpunit/tests/kses.php +++ b/tests/phpunit/tests/kses.php @@ -562,47 +562,47 @@ public static function data_normalize_entities(): array { ':' => array( ':', ':' ), '&#XYZZY;' => array( '&#XYZZY;', '&#XYZZY;' ), - 'Named entity: &' => array( '♠', '♠' ), - 'Named entity: &' => array( '♠', '♠' ), - 'Named entity: ♠' => array( '♠', '♠' ), - 'Named entity: ¹' => array( '¹', '¹' ), - 'Named entity: ²' => array( '²', '²' ), - 'Named entity: ³' => array( '³', '³' ), - 'Named entity: ¼' => array( '¼', '¼' ), - 'Named entity: ½' => array( '½', '½' ), - 'Named entity: ¾' => array( '¾', '¾' ), - 'Named entity: ∴' => array( '∴', '∴' ), - - 'Numeric entity ( )' => array( ' ', ' ' ), - 'Numeric entity " (")' => array( '"', '"' ), - 'Numeric entity " (")' => array( '"', '"' ), - 'Numeric entity & (&)' => array( '&', '&' ), - "Numeric entity ' (')" => array( ''', ''' ), - 'Numeric entity 😍 (😍)' => array( '😍', '😍' ), - 'Numeric entity 😍 (😍)' => array( '😍', '😍' ), - - 'Hex entity ( )' => array( ' ', ' ' ), - 'Hex entity " (")' => array( '"', '"' ), - 'Hex entity " (")' => array( '"', '"' ), - 'Hex entity & (&)' => array( '&', '&' ), - "Hex entity ' (')" => array( ''', ''' ), - 'Hex entity 😍 (😍)' => array( '😍', '😍' ), - 'Hex entity 😍 (😍)' => array( '😍', '😍' ), - - 'HEX ENTITY " (")' => array( '"', '"' ), - 'HEX ENTITY & (&)' => array( '&', '&' ), - "HEX ENTITY ' (')" => array( ''', ''' ), - 'HEX ENTITY 😍 (😍)' => array( '😍', '😍' ), - - 'Encoded named entity &' => array( '&', '&' ), - 'Encoded named entity &' => array( '&', '&' ), - 'Encoded named entity &' => array( '&', '&' ), + 'Named ref &' => array( '♠', '♠' ), + 'Named ref &' => array( '♠', '♠' ), + 'Named ref ♠' => array( '♠', '♠' ), + 'Named ref ¹' => array( '¹', '¹' ), + 'Named ref ²' => array( '²', '²' ), + 'Named ref ³' => array( '³', '³' ), + 'Named ref ¼' => array( '¼', '¼' ), + 'Named ref ½' => array( '½', '½' ), + 'Named ref ¾' => array( '¾', '¾' ), + 'Named ref ∴' => array( '∴', '∴' ), + + 'Decimal ref ( )' => array( ' ', ' ' ), + 'Decimal ref " (")' => array( '"', '"' ), + 'Decimal ref " (")' => array( '"', '"' ), + 'Decimal ref & (&)' => array( '&', '&' ), + "Decimal ref ' (')" => array( ''', ''' ), + 'Decimal ref 😍 (😍)' => array( '😍', '😍' ), + 'Decimal ref 😍 (😍)' => array( '😍', '😍' ), + + 'Hex ref ( )' => array( ' ', ' ' ), + 'Hex ref " (")' => array( '"', '"' ), + 'Hex ref " (")' => array( '"', '"' ), + 'Hex ref & (&)' => array( '&', '&' ), + "Hex ref ' (')" => array( ''', ''' ), + 'Hex ref 😍 (😍)' => array( '😍', '😍' ), + 'Hex ref 😍 (😍)' => array( '😍', '😍' ), + + 'HEX REF " (")' => array( '"', '"' ), + 'HEX REF & (&)' => array( '&', '&' ), + "HEX REF ' (')" => array( ''', ''' ), + 'HEX REF 😍 (😍)' => array( '😍', '😍' ), + + 'Encoded named ref &' => array( '&', '&' ), + 'Encoded named ref &' => array( '&', '&' ), + 'Encoded named ref &' => array( '&', '&' ), /* * The codepoint value here is outside of the valid unicode range whose * maximum is 0x10FFFF or 1114111. */ - 'Invalid numeric unicode �' => array( '�', '�' ), + 'Invalid decimal unicode �' => array( '�', '�' ), 'Invalid hex unicode �' => array( '�', '�' ), ); }