From 091d72b25f1bed96180c2a6e0e16eeefb1501bca Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 27 Feb 2026 17:32:28 +0100 Subject: [PATCH 01/13] add tests --- .../wpHtmlProcessorModifiableText.php | 41 +++++++++++++++++++ .../wpHtmlTagProcessorModifiableText.php | 41 +++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index 08a4514fa14fd..b4e55be3c0e13 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -68,4 +68,45 @@ public static function data_modifiable_text_special_textarea() { ), ); } + + /** + * Ensures that `set_modifiable_text()` returns false for elements that share + * tag names with HTML atomic elements but are in non-HTML namespaces. + * + * @ticket 64751 + * @dataProvider data_set_modifiable_text_fails_for_non_html_namespace_elements + */ + public function test_set_modifiable_text_fails_for_non_html_namespace_elements( + string $html, + string $expected_namespace, + string $expected_tag + ) { + $processor = WP_HTML_Processor::create_fragment( $html ); + while ( $processor->next_tag() && $expected_tag !== $processor->get_tag() ) { + continue; + } + $this->assertSame( $expected_tag, $processor->get_tag(), 'Failed to find target tag.' ); + $this->assertSame( $expected_namespace, $processor->get_namespace(), 'Unexpected namespace.' ); + $this->assertFalse( + $processor->set_modifiable_text( 'test' ), + "set_modifiable_text() should return false for {$expected_namespace}:{$expected_tag}." + ); + $this->assertSame( + $html, + $processor->get_updated_html(), + 'HTML should be unchanged after rejected set_modifiable_text().' + ); + } + + /** + * Data provider. + */ + public static function data_set_modifiable_text_fails_for_non_html_namespace_elements(): array { + return array( + 'SVG TEXTAREA' => array( '', 'svg', 'TEXTAREA' ), + 'SVG TITLE' => array( '', 'svg', 'TITLE' ), + 'SVG STYLE' => array( '', 'svg', 'STYLE' ), + 'SVG SCRIPT' => array( '', 'svg', 'SCRIPT' ), + ); + } } diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php index 0a8ecc0976d66..088e534942264 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php @@ -39,6 +39,47 @@ public function test_get_modifiable_text_is_idempotent() { } } + /** + * Ensures that `set_modifiable_text()` returns false for elements that share + * tag names with HTML atomic elements when parsed in a non-HTML namespace. + * + * @ticket 64751 + * @dataProvider data_set_modifiable_text_fails_for_non_html_namespace_elements + */ + public function test_set_modifiable_text_fails_for_non_html_namespace_elements( + string $html, + string $expected_tag + ) { + $processor = new WP_HTML_Tag_Processor( $html ); + $processor->change_parsing_namespace( 'svg' ); + $processor->next_token(); + $this->assertSame( $expected_tag, $processor->get_tag(), 'Failed to find target tag.' ); + $this->assertSame( 'svg', $processor->get_namespace() ); + $this->assertFalse( + $processor->set_modifiable_text( 'test' ), + "set_modifiable_text() should return false for svg:{$expected_tag}." + ); + $this->assertSame( + $html, + $processor->get_updated_html(), + 'HTML should be unchanged after rejected set_modifiable_text().' + ); + } + + /** + * Data provider. + * + * @return array[] + */ + public static function data_set_modifiable_text_fails_for_non_html_namespace_elements() { + return array( + 'SVG TEXTAREA' => array( '', 'TEXTAREA' ), + 'SVG TITLE' => array( '', 'TITLE' ), + 'SVG STYLE' => array( '', 'STYLE' ), + 'SVG SCRIPT' => array( '', 'SCRIPT' ), + ); + } + /** * Data provider. * From 7babedf009d586b89a93813d50c217746b1bc60c Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 27 Feb 2026 17:55:00 +0100 Subject: [PATCH 02/13] Improve and expand html mod text tests --- .../wpHtmlProcessorModifiableText.php | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index b4e55be3c0e13..137ed31d12096 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -71,12 +71,15 @@ public static function data_modifiable_text_special_textarea() { /** * Ensures that `set_modifiable_text()` returns false for elements that share - * tag names with HTML atomic elements but are in non-HTML namespaces. + * not sepcial "atomic" elements. + * + * This includes atomic-like foreign elements (`
`). * * @ticket 64751 - * @dataProvider data_set_modifiable_text_fails_for_non_html_namespace_elements + * @dataProvider data_set_modifiable_fails_non_atomic_tags */ - public function test_set_modifiable_text_fails_for_non_html_namespace_elements( + public function test_set_modifiable_fails_non_atomic_tags( string $html, string $expected_namespace, string $expected_tag @@ -101,12 +104,26 @@ public function test_set_modifiable_text_fails_for_non_html_namespace_elements( /** * Data provider. */ - public static function data_set_modifiable_text_fails_for_non_html_namespace_elements(): array { + public static function data_set_modifiable_fails_non_atomic_tags(): array { return array( - 'SVG TEXTAREA' => array( '', 'svg', 'TEXTAREA' ), - 'SVG TITLE' => array( '', 'svg', 'TITLE' ), - 'SVG STYLE' => array( '', 'svg', 'STYLE' ), - 'SVG SCRIPT' => array( '', 'svg', 'SCRIPT' ), + // Plain HTML tags. + 'html DIV' => array( '
', 'html', 'DIV' ), + + // Foreign elements with non-atomic tags. + 'svg PATH' => array( '', 'svg', 'PATH' ), + 'svg PATH (self-closing)' => array( '', 'svg', 'PATH' ), + 'math MTEXT' => array( '', 'math', 'MTEXT' ), + 'math MSPACE (self-closing)' => array( '', 'math', 'MSPACE' ), + + // Foreign elements with atomic-like tags. + 'svg TEXTAREA' => array( '', 'svg', 'TEXTAREA' ), + 'svg TITLE' => array( '', 'svg', 'TITLE' ), + 'svg STYLE' => array( '', 'svg', 'STYLE' ), + 'svg SCRIPT' => array( '', 'svg', 'SCRIPT' ), + 'math TEXTAREA' => array( '', 'math', 'TEXTAREA' ), + 'math TITLE' => array( '', 'math', 'TITLE' ), + 'math STYLE' => array( '', 'math', 'STYLE' ), + 'math SCRIPT' => array( '', 'math', 'SCRIPT' ), ); } } From 23c15f59f353dbb450908ef3e6103a56424a375c Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 27 Feb 2026 18:33:41 +0100 Subject: [PATCH 03/13] fix up tag proc mod text tests --- .../wpHtmlTagProcessorModifiableText.php | 99 +++++++++++-------- 1 file changed, 58 insertions(+), 41 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php index 088e534942264..eb0c0162dfd81 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php @@ -39,47 +39,6 @@ public function test_get_modifiable_text_is_idempotent() { } } - /** - * Ensures that `set_modifiable_text()` returns false for elements that share - * tag names with HTML atomic elements when parsed in a non-HTML namespace. - * - * @ticket 64751 - * @dataProvider data_set_modifiable_text_fails_for_non_html_namespace_elements - */ - public function test_set_modifiable_text_fails_for_non_html_namespace_elements( - string $html, - string $expected_tag - ) { - $processor = new WP_HTML_Tag_Processor( $html ); - $processor->change_parsing_namespace( 'svg' ); - $processor->next_token(); - $this->assertSame( $expected_tag, $processor->get_tag(), 'Failed to find target tag.' ); - $this->assertSame( 'svg', $processor->get_namespace() ); - $this->assertFalse( - $processor->set_modifiable_text( 'test' ), - "set_modifiable_text() should return false for svg:{$expected_tag}." - ); - $this->assertSame( - $html, - $processor->get_updated_html(), - 'HTML should be unchanged after rejected set_modifiable_text().' - ); - } - - /** - * Data provider. - * - * @return array[] - */ - public static function data_set_modifiable_text_fails_for_non_html_namespace_elements() { - return array( - 'SVG TEXTAREA' => array( '', 'TEXTAREA' ), - 'SVG TITLE' => array( '', 'TITLE' ), - 'SVG STYLE' => array( '', 'STYLE' ), - 'SVG SCRIPT' => array( '', 'SCRIPT' ), - ); - } - /** * Data provider. * @@ -705,4 +664,62 @@ public function test_modifiable_text_special_textarea() { 'Should have preserved the leading newline in the content.' ); } + + /** + * Ensures that `set_modifiable_text()` returns false for elements that are + * not special "atomic" elements. + * + * This includes atomic-like foreign elements as well as non-atomic foreign elements. + * + * @ticket 64751 + * @dataProvider data_set_modifiable_fails_non_atomic_tags + */ + public function test_set_modifiable_fails_non_atomic_tags( + string $html, + string $parsing_namespace, + string $expected_tag + ) { + $processor = new WP_HTML_Tag_Processor( $html ); + $processor->change_parsing_namespace( $parsing_namespace ); + $processor->next_token(); + $this->assertSame( $expected_tag, $processor->get_tag(), 'Failed to find target tag.' ); + $this->assertFalse( + $processor->set_modifiable_text( 'test' ), + "set_modifiable_text() should return false for {$parsing_namespace}:{$expected_tag}." + ); + $this->assertSame( + $html, + $processor->get_updated_html(), + 'HTML should be unchanged after rejected set_modifiable_text().' + ); + } + + /** + * Data provider. + * + * @return array[] + */ + public static function data_set_modifiable_fails_non_atomic_tags() { + return array( + // Plain HTML tags. + 'html DIV' => array( '
', 'html', 'DIV' ), + + // Foreign elements with non-atomic tags. + 'svg PATH' => array( '', 'svg', 'PATH' ), + 'svg PATH (self-closing)' => array( '', 'svg', 'PATH' ), + 'math MTEXT' => array( '', 'math', 'MTEXT' ), + 'math MSPACE (self-closing)' => array( '', 'math', 'MSPACE' ), + + // Foreign elements with atomic-like tags. + 'svg TEXTAREA' => array( '', 'svg', 'TEXTAREA' ), + 'svg TITLE' => array( '', 'svg', 'TITLE' ), + 'svg STYLE' => array( '', 'svg', 'STYLE' ), + 'svg SCRIPT' => array( '', 'svg', 'SCRIPT' ), + 'math TEXTAREA' => array( '', 'math', 'TEXTAREA' ), + 'math TITLE' => array( '', 'math', 'TITLE' ), + 'math STYLE' => array( '', 'math', 'STYLE' ), + 'math SCRIPT' => array( '', 'math', 'SCRIPT' ), + ); + } + } From 34925d5f6c6884ea093749d3c6bad94080325f8b Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 27 Feb 2026 18:35:49 +0100 Subject: [PATCH 04/13] Fix issue --- .../html-api/class-wp-html-tag-processor.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php index 22e7c25f64b62..2484214c76874 100644 --- a/src/wp-includes/html-api/class-wp-html-tag-processor.php +++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php @@ -3807,7 +3807,20 @@ public function set_modifiable_text( string $plaintext_content ): bool { return true; } - if ( self::STATE_MATCHED_TAG !== $this->parser_state ) { + /* + * The rest of this function handles modifiable text for special "atomic" HTML elements: + * + * - SCRIPT + * - STYLE + * - TEXTAREA + * - TITLE + * + * Only tags in the HTML namespace should be processed. + */ + if ( + self::STATE_MATCHED_TAG !== $this->parser_state || + 'html' !== $this->get_namespace() + ) { return false; } From 3e88f34ccedb91e8716b27e0ef0d5a224e13ea99 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 27 Feb 2026 18:41:56 +0100 Subject: [PATCH 05/13] Remove excessively specific tag name documentation --- src/wp-includes/html-api/class-wp-html-tag-processor.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php index 2484214c76874..d544f0f49ba73 100644 --- a/src/wp-includes/html-api/class-wp-html-tag-processor.php +++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php @@ -3808,13 +3808,7 @@ public function set_modifiable_text( string $plaintext_content ): bool { } /* - * The rest of this function handles modifiable text for special "atomic" HTML elements: - * - * - SCRIPT - * - STYLE - * - TEXTAREA - * - TITLE - * + * The rest of this function handles modifiable text for special "atomic" HTML elements. * Only tags in the HTML namespace should be processed. */ if ( From c5ef32a83418f5edaf574f3fab6d6692123af87a Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 27 Feb 2026 19:18:55 +0100 Subject: [PATCH 06/13] Fix typos in code comment Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index 137ed31d12096..3547bf4842cc8 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -70,8 +70,7 @@ public static function data_modifiable_text_special_textarea() { } /** - * Ensures that `set_modifiable_text()` returns false for elements that share - * not sepcial "atomic" elements. + * Ensures that `set_modifiable_text()` returns false for elements that are not special "atomic" elements. * * This includes atomic-like foreign elements (`
`). From cfb6a53c3456d1c9fa111662f4da138633768619 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 27 Feb 2026 21:30:43 +0100 Subject: [PATCH 07/13] Improve types in tests Co-authored-by: Weston Ruter --- .../tests/html-api/wpHtmlProcessorModifiableText.php | 5 ++++- .../tests/html-api/wpHtmlTagProcessorModifiableText.php | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index 3547bf4842cc8..554a33589ecba 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -82,8 +82,9 @@ public function test_set_modifiable_fails_non_atomic_tags( string $html, string $expected_namespace, string $expected_tag - ) { + ): void { $processor = WP_HTML_Processor::create_fragment( $html ); + $this->assertInstanceOf( WP_HTML_Tag_Processor::class, $processor ); while ( $processor->next_tag() && $expected_tag !== $processor->get_tag() ) { continue; } @@ -102,6 +103,8 @@ public function test_set_modifiable_fails_non_atomic_tags( /** * Data provider. + * + * @return array */ public static function data_set_modifiable_fails_non_atomic_tags(): array { return array( diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php index eb0c0162dfd81..b978c0f9464b0 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php @@ -678,7 +678,7 @@ public function test_set_modifiable_fails_non_atomic_tags( string $html, string $parsing_namespace, string $expected_tag - ) { + ): void { $processor = new WP_HTML_Tag_Processor( $html ); $processor->change_parsing_namespace( $parsing_namespace ); $processor->next_token(); @@ -697,9 +697,9 @@ public function test_set_modifiable_fails_non_atomic_tags( /** * Data provider. * - * @return array[] + * @return array */ - public static function data_set_modifiable_fails_non_atomic_tags() { + public static function data_set_modifiable_fails_non_atomic_tags(): array { return array( // Plain HTML tags. 'html DIV' => array( '
', 'html', 'DIV' ), From 893c28de384be3fd9b8c4c656cf75d0157491292 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Sat, 28 Feb 2026 08:42:07 +0100 Subject: [PATCH 08/13] Clean up whitespace Co-authored-by: Weston Ruter --- tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index 554a33589ecba..3a322c1c133fe 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -103,7 +103,7 @@ public function test_set_modifiable_fails_non_atomic_tags( /** * Data provider. - * + * * @return array */ public static function data_set_modifiable_fails_non_atomic_tags(): array { From 92a127b0bb08cf57738a4aaa937f82c099d7fc4e Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 2 Mar 2026 10:38:08 +0100 Subject: [PATCH 09/13] fix lint --- .../phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php index b978c0f9464b0..988f9c9696b74 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php @@ -721,5 +721,4 @@ public static function data_set_modifiable_fails_non_atomic_tags(): array { 'math SCRIPT' => array( '', 'math', 'SCRIPT' ), ); } - } From dc65bb38960bf63a191f8e3a1d125c7ac66bbfe1 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 2 Mar 2026 10:41:31 +0100 Subject: [PATCH 10/13] Improve test types Improve some test types from [61754] --- .../tests/html-api/wpHtmlProcessorModifiableText.php | 6 +++--- .../tests/html-api/wpHtmlTagProcessorModifiableText.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index 3a322c1c133fe..1734c646d4909 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -24,7 +24,7 @@ class Tests_HtmlApi_WpHtmlProcessorModifiableText extends WP_UnitTestCase { * @param string $set_text Text to set. * @param string $expected_html Expected HTML output. */ - public function test_modifiable_text_special_textarea( string $set_text, string $expected_html ) { + public function test_modifiable_text_special_textarea( string $set_text, string $expected_html ): void { $processor = WP_HTML_Processor::create_fragment( '' ); $processor->next_token(); $processor->set_modifiable_text( $set_text ); @@ -50,9 +50,9 @@ public function test_modifiable_text_special_textarea( string $set_text, string /** * Data provider. * - * @return array[] + * @return array */ - public static function data_modifiable_text_special_textarea() { + public static function data_modifiable_text_special_textarea(): array { return array( 'Leading newline' => array( "\nAFTER NEWLINE", diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php index 988f9c9696b74..509652cf4036d 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php @@ -644,7 +644,7 @@ public function test_json_auto_escaping() { * * @ticket 64609 */ - public function test_modifiable_text_special_textarea() { + public function test_modifiable_text_special_textarea(): void { $processor = new WP_HTML_Tag_Processor( '' ); $processor->next_token(); $processor->set_modifiable_text( "\nAFTER NEWLINE" ); From 2b443a8ee82c4ac5231740965aa9f8ecbb9b5c2b Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 2 Mar 2026 10:50:08 +0100 Subject: [PATCH 11/13] search for target tag directly --- .../tests/html-api/wpHtmlProcessorModifiableText.php | 9 +++------ .../tests/html-api/wpHtmlTagProcessorModifiableText.php | 7 +++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index 1734c646d4909..b4b805a2c9a4f 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -81,18 +81,15 @@ public static function data_modifiable_text_special_textarea(): array { public function test_set_modifiable_fails_non_atomic_tags( string $html, string $expected_namespace, - string $expected_tag + string $target_tag ): void { $processor = WP_HTML_Processor::create_fragment( $html ); $this->assertInstanceOf( WP_HTML_Tag_Processor::class, $processor ); - while ( $processor->next_tag() && $expected_tag !== $processor->get_tag() ) { - continue; - } - $this->assertSame( $expected_tag, $processor->get_tag(), 'Failed to find target tag.' ); + $this->assertTrue( $processor->next_tag( $target_tag ), 'Failed to find target tag.' ); $this->assertSame( $expected_namespace, $processor->get_namespace(), 'Unexpected namespace.' ); $this->assertFalse( $processor->set_modifiable_text( 'test' ), - "set_modifiable_text() should return false for {$expected_namespace}:{$expected_tag}." + "set_modifiable_text() should return false for {$expected_namespace}:{$target_tag}." ); $this->assertSame( $html, diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php index 509652cf4036d..f43d1fffaad0e 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php @@ -677,15 +677,14 @@ public function test_modifiable_text_special_textarea(): void { public function test_set_modifiable_fails_non_atomic_tags( string $html, string $parsing_namespace, - string $expected_tag + string $target_tag ): void { $processor = new WP_HTML_Tag_Processor( $html ); $processor->change_parsing_namespace( $parsing_namespace ); - $processor->next_token(); - $this->assertSame( $expected_tag, $processor->get_tag(), 'Failed to find target tag.' ); + $this->assertTrue( $processor->next_tag( $target_tag ), 'Failed to find target tag.' ); $this->assertFalse( $processor->set_modifiable_text( 'test' ), - "set_modifiable_text() should return false for {$parsing_namespace}:{$expected_tag}." + "set_modifiable_text() should return false for {$parsing_namespace}:{$target_tag}." ); $this->assertSame( $html, From bfae594565f27bcc22eabebe2a91fa9beed3b317 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 2 Mar 2026 10:55:59 +0100 Subject: [PATCH 12/13] Remove namespace checking from set_modifiable_text tests --- .../wpHtmlProcessorModifiableText.php | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index b4b805a2c9a4f..cc17195f35856 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -80,16 +80,14 @@ public static function data_modifiable_text_special_textarea(): array { */ public function test_set_modifiable_fails_non_atomic_tags( string $html, - string $expected_namespace, string $target_tag ): void { $processor = WP_HTML_Processor::create_fragment( $html ); $this->assertInstanceOf( WP_HTML_Tag_Processor::class, $processor ); $this->assertTrue( $processor->next_tag( $target_tag ), 'Failed to find target tag.' ); - $this->assertSame( $expected_namespace, $processor->get_namespace(), 'Unexpected namespace.' ); $this->assertFalse( $processor->set_modifiable_text( 'test' ), - "set_modifiable_text() should return false for {$expected_namespace}:{$target_tag}." + "set_modifiable_text() should return false on {$processor->get_namespace()}:{$processor->get_qualified_tag_name()}." ); $this->assertSame( $html, @@ -106,23 +104,23 @@ public function test_set_modifiable_fails_non_atomic_tags( public static function data_set_modifiable_fails_non_atomic_tags(): array { return array( // Plain HTML tags. - 'html DIV' => array( '
', 'html', 'DIV' ), + 'html DIV' => array( '
', 'DIV' ), // Foreign elements with non-atomic tags. - 'svg PATH' => array( '', 'svg', 'PATH' ), - 'svg PATH (self-closing)' => array( '', 'svg', 'PATH' ), - 'math MTEXT' => array( '', 'math', 'MTEXT' ), - 'math MSPACE (self-closing)' => array( '', 'math', 'MSPACE' ), + 'svg PATH' => array( '', 'PATH' ), + 'svg PATH (self-closing)' => array( '', 'PATH' ), + 'math MTEXT' => array( '', 'MTEXT' ), + 'math MSPACE (self-closing)' => array( '', 'MSPACE' ), // Foreign elements with atomic-like tags. - 'svg TEXTAREA' => array( '', 'svg', 'TEXTAREA' ), - 'svg TITLE' => array( '', 'svg', 'TITLE' ), - 'svg STYLE' => array( '', 'svg', 'STYLE' ), - 'svg SCRIPT' => array( '', 'svg', 'SCRIPT' ), - 'math TEXTAREA' => array( '', 'math', 'TEXTAREA' ), - 'math TITLE' => array( '', 'math', 'TITLE' ), - 'math STYLE' => array( '', 'math', 'STYLE' ), - 'math SCRIPT' => array( '', 'math', 'SCRIPT' ), + 'svg TEXTAREA' => array( '', 'TEXTAREA' ), + 'svg TITLE' => array( '', 'TITLE' ), + 'svg STYLE' => array( '', 'STYLE' ), + 'svg SCRIPT' => array( '', 'SCRIPT' ), + 'math TEXTAREA' => array( '', 'TEXTAREA' ), + 'math TITLE' => array( '', 'TITLE' ), + 'math STYLE' => array( '', 'STYLE' ), + 'math SCRIPT' => array( '', 'SCRIPT' ), ); } } From dd8b09e184e92c4d6e95d2686479d5865e934377 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 2 Mar 2026 21:04:45 +0100 Subject: [PATCH 13/13] Assert processor is not null, add debug note --- tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index cc17195f35856..5d093ae05dd07 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -83,7 +83,7 @@ public function test_set_modifiable_fails_non_atomic_tags( string $target_tag ): void { $processor = WP_HTML_Processor::create_fragment( $html ); - $this->assertInstanceOf( WP_HTML_Tag_Processor::class, $processor ); + $this->assertNotNull( $processor, 'Failed to create a processor.' ); $this->assertTrue( $processor->next_tag( $target_tag ), 'Failed to find target tag.' ); $this->assertFalse( $processor->set_modifiable_text( 'test' ),