From 4f755da0281f4c980107e47bea53544ed976772c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 16 Dec 2025 19:42:49 +0000 Subject: [PATCH 1/8] Initial plan From 9254cd0680529680b2a60a904b53f214b49ead7f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 16 Dec 2025 19:54:43 +0000 Subject: [PATCH 2/8] Add unit tests for is_javascript_script_tag and is_json_script_tag methods Co-authored-by: sirreal <841763+sirreal@users.noreply.github.com> --- .../html-api/wpHtmlTagProcessorScriptTag.php | 238 ++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php new file mode 100644 index 0000000000000..eb1d11c0ed51a --- /dev/null +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php @@ -0,0 +1,238 @@ +next_tag(); + + $this->assertSame( + $expected_result, + $processor->is_javascript_script_tag(), + 'Failed to correctly identify JavaScript script tag' + ); + } + + /** + * Data provider for test_is_javascript_script_tag. + * + * @return array[] + */ + public static function data_is_javascript_script_tag() { + return array( + // Script tags without type or language attributes - should be JavaScript. + 'Script tag without attributes' => array( '', true ), + 'Script tag with other attributes' => array( '', true ), + + // Script tags with empty type attribute - should be JavaScript. + 'Script tag with empty type attribute' => array( '', true ), + 'Script tag with boolean type attribute' => array( '', true ), + + // Script tags without type but with language attribute - should be JavaScript. + 'Script tag with empty language attribute' => array( '', true ), + 'Script tag with boolean language attribute' => array( '', true ), + + // Script tags with JavaScript MIME types - should be JavaScript. + 'Script tag with application/ecmascript' => array( '', true ), + 'Script tag with application/javascript' => array( '', true ), + 'Script tag with application/x-ecmascript' => array( '', true ), + 'Script tag with application/x-javascript' => array( '', true ), + 'Script tag with text/ecmascript' => array( '', true ), + 'Script tag with text/javascript' => array( '', true ), + 'Script tag with text/javascript1.0' => array( '', true ), + 'Script tag with text/javascript1.1' => array( '', true ), + 'Script tag with text/javascript1.2' => array( '', true ), + 'Script tag with text/javascript1.3' => array( '', true ), + 'Script tag with text/javascript1.4' => array( '', true ), + 'Script tag with text/javascript1.5' => array( '', true ), + 'Script tag with text/jscript' => array( '', true ), + 'Script tag with text/livescript' => array( '', true ), + 'Script tag with text/x-ecmascript' => array( '', true ), + 'Script tag with text/x-javascript' => array( '', true ), + + // Case-insensitive matching for JavaScript MIME types. + 'Script tag with UPPERCASE type' => array( '', true ), + 'Script tag with MixedCase type' => array( '', true ), + 'Script tag with APPLICATION/JAVASCRIPT' => array( '', true ), + + // Script tags with module type - should be JavaScript. + 'Script tag with module type' => array( '', true ), + 'Script tag with MODULE type uppercase' => array( '', true ), + 'Script tag with MoDuLe type mixed case' => array( '', true ), + + // Script tags with whitespace around type - should strip whitespace. + 'Script tag with leading whitespace' => array( '', true ), + 'Script tag with trailing whitespace' => array( '', true ), + 'Script tag with surrounding whitespace' => array( '', true ), + 'Script tag with tab whitespace' => array( "", true ), + 'Script tag with newline whitespace' => array( "", true ), + 'Script tag with mixed whitespace' => array( "", true ), + + // Script tags with language attribute and non-empty value - should use text/{language}. + 'Script tag with language="javascript"' => array( '', true ), + 'Script tag with language="JavaScript"' => array( '', true ), + 'Script tag with language="ecmascript"' => array( '', true ), + 'Script tag with language="jscript"' => array( '', true ), + 'Script tag with language="livescript"' => array( '', true ), + + // Non-JavaScript script tags - should NOT be JavaScript. + 'Script tag with importmap type' => array( '', false ), + 'Script tag with speculationrules type' => array( '', false ), + 'Script tag with application/json type' => array( '', false ), + 'Script tag with text/json type' => array( '', false ), + 'Script tag with unknown MIME type' => array( '', false ), + 'Script tag with application/xml type' => array( '', false ), + 'Script tag with random type' => array( '', false ), + + // Non-script tags - should NOT be JavaScript. + 'DIV tag' => array( '
', false ), + 'SPAN tag' => array( '', false ), + 'P tag' => array( '', false ), + ); + } + + /** + * @ticket TBD + * + * @covers WP_HTML_Tag_Processor::is_javascript_script_tag + */ + public function test_is_javascript_script_tag_returns_false_before_finding_tags() { + $processor = new WP_HTML_Tag_Processor( '' ); + + $this->assertFalse( + $processor->is_javascript_script_tag(), + 'Should return false when no tag has been selected' + ); + } + + /** + * @ticket TBD + * + * @covers WP_HTML_Tag_Processor::is_javascript_script_tag + */ + public function test_is_javascript_script_tag_returns_false_for_non_html_namespace() { + $processor = new WP_HTML_Tag_Processor( '' ); + $processor->next_tag( 'SCRIPT' ); + + $this->assertFalse( + $processor->is_javascript_script_tag(), + 'Should return false for script tags in non-HTML namespace' + ); + } + + /** + * @ticket TBD + * + * @covers WP_HTML_Tag_Processor::is_json_script_tag + * + * @dataProvider data_is_json_script_tag + * + * @param string $html HTML containing a script tag. + * @param bool $expected_result Whether the script tag should be identified as JSON. + */ + public function test_is_json_script_tag( $html, $expected_result ) { + $processor = new WP_HTML_Tag_Processor( $html ); + $processor->next_tag(); + + $this->assertSame( + $expected_result, + $processor->is_json_script_tag(), + 'Failed to correctly identify JSON script tag' + ); + } + + /** + * Data provider for test_is_json_script_tag. + * + * @return array[] + */ + public static function data_is_json_script_tag() { + return array( + // JSON MIME types - should be JSON. + 'Script tag with application/json type' => array( '', true ), + 'Script tag with text/json type' => array( '', true ), + + // importmap and speculationrules - should be JSON. + 'Script tag with importmap type' => array( '', true ), + 'Script tag with speculationrules type' => array( '', true ), + + // Case-insensitive matching for JSON types. + 'Script tag with APPLICATION/JSON uppercase' => array( '', true ), + 'Script tag with Text/Json mixed case' => array( '', true ), + 'Script tag with IMPORTMAP uppercase' => array( '', true ), + 'Script tag with ImportMap mixed case' => array( '', true ), + 'Script tag with SPECULATIONRULES uppercase' => array( '', true ), + 'Script tag with SpeculationRules mixed' => array( '', true ), + + // Whitespace handling - should strip whitespace. + 'Script tag with leading whitespace' => array( '', true ), + 'Script tag with trailing whitespace' => array( '', true ), + 'Script tag with surrounding whitespace' => array( '', true ), + 'Script tag with tab whitespace' => array( "", true ), + 'Script tag with newline whitespace' => array( "", true ), + 'Script tag with mixed whitespace' => array( "", true ), + + // Non-JSON script tags - should NOT be JSON. + 'Script tag without type attribute' => array( '', false ), + 'Script tag with empty type attribute' => array( '', false ), + 'Script tag with boolean type attribute' => array( '', false ), + 'Script tag with text/javascript type' => array( '', false ), + 'Script tag with module type' => array( '', false ), + 'Script tag with unknown MIME type' => array( '', false ), + 'Script tag with application/xml type' => array( '', false ), + + // Non-script tags - should NOT be JSON. + 'DIV tag' => array( '', false ), + 'SPAN tag' => array( '', false ), + 'P tag' => array( '', false ), + ); + } + + /** + * @ticket TBD + * + * @covers WP_HTML_Tag_Processor::is_json_script_tag + */ + public function test_is_json_script_tag_returns_false_before_finding_tags() { + $processor = new WP_HTML_Tag_Processor( '' ); + + $this->assertFalse( + $processor->is_json_script_tag(), + 'Should return false when no tag has been selected' + ); + } + + /** + * @ticket TBD + * + * @covers WP_HTML_Tag_Processor::is_json_script_tag + */ + public function test_is_json_script_tag_returns_false_for_non_html_namespace() { + $processor = new WP_HTML_Tag_Processor( '' ); + $processor->next_tag( 'SCRIPT' ); + + $this->assertFalse( + $processor->is_json_script_tag(), + 'Should return false for script tags in non-HTML namespace' + ); + } +} From a86cf86d3e7d373a718f3e7176394a7db02787b2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 16 Dec 2025 20:19:08 +0000 Subject: [PATCH 3/8] Add type declarations to test method parameters Co-authored-by: sirreal <841763+sirreal@users.noreply.github.com> --- tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php index eb1d11c0ed51a..b03098b0757a9 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php @@ -21,7 +21,7 @@ class Tests_HtmlApi_WpHtmlTagProcessorScriptTag extends WP_UnitTestCase { * @param string $html HTML containing a script tag. * @param bool $expected_result Whether the script tag should be identified as JavaScript. */ - public function test_is_javascript_script_tag( $html, $expected_result ) { + public function test_is_javascript_script_tag( string $html, bool $expected_result ) { $processor = new WP_HTML_Tag_Processor( $html ); $processor->next_tag(); @@ -149,7 +149,7 @@ public function test_is_javascript_script_tag_returns_false_for_non_html_namespa * @param string $html HTML containing a script tag. * @param bool $expected_result Whether the script tag should be identified as JSON. */ - public function test_is_json_script_tag( $html, $expected_result ) { + public function test_is_json_script_tag( string $html, bool $expected_result ) { $processor = new WP_HTML_Tag_Processor( $html ); $processor->next_tag(); From 697881ccfdb511c59b373ce93ed080fe11bbe1f9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 16 Dec 2025 20:22:03 +0000 Subject: [PATCH 4/8] Use text node instead of script tag in no-tag-selected tests Co-authored-by: sirreal <841763+sirreal@users.noreply.github.com> --- tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php index b03098b0757a9..ee2773ebc5536 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php @@ -116,7 +116,7 @@ public static function data_is_javascript_script_tag() { * @covers WP_HTML_Tag_Processor::is_javascript_script_tag */ public function test_is_javascript_script_tag_returns_false_before_finding_tags() { - $processor = new WP_HTML_Tag_Processor( '' ); + $processor = new WP_HTML_Tag_Processor( 'Just some text' ); $this->assertFalse( $processor->is_javascript_script_tag(), @@ -213,7 +213,7 @@ public static function data_is_json_script_tag() { * @covers WP_HTML_Tag_Processor::is_json_script_tag */ public function test_is_json_script_tag_returns_false_before_finding_tags() { - $processor = new WP_HTML_Tag_Processor( '' ); + $processor = new WP_HTML_Tag_Processor( 'Just some text' ); $this->assertFalse( $processor->is_json_script_tag(), From 727c0901d9ca5e861ead39f6bf1bc9cac69a8a94 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Dec 2025 10:11:05 +0000 Subject: [PATCH 5/8] Call next_token() to position at text node in edge case tests Co-authored-by: sirreal <841763+sirreal@users.noreply.github.com> --- tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php index ee2773ebc5536..f830351f51c23 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php @@ -117,6 +117,7 @@ public static function data_is_javascript_script_tag() { */ public function test_is_javascript_script_tag_returns_false_before_finding_tags() { $processor = new WP_HTML_Tag_Processor( 'Just some text' ); + $processor->next_token(); $this->assertFalse( $processor->is_javascript_script_tag(), @@ -214,6 +215,7 @@ public static function data_is_json_script_tag() { */ public function test_is_json_script_tag_returns_false_before_finding_tags() { $processor = new WP_HTML_Tag_Processor( 'Just some text' ); + $processor->next_token(); $this->assertFalse( $processor->is_json_script_tag(), From e5476e29d958d65d71bbd6142b1f0455440432fb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Dec 2025 10:16:46 +0000 Subject: [PATCH 6/8] Add SCRIPT tag assertions and update assertion messages Co-authored-by: sirreal <841763+sirreal@users.noreply.github.com> --- .../phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php index f830351f51c23..852a280b800be 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php @@ -25,6 +25,7 @@ public function test_is_javascript_script_tag( string $html, bool $expected_resu $processor = new WP_HTML_Tag_Processor( $html ); $processor->next_tag(); + $this->assertSame( 'SCRIPT', $processor->get_tag(), 'Should be positioned on a SCRIPT tag' ); $this->assertSame( $expected_result, $processor->is_javascript_script_tag(), @@ -121,7 +122,7 @@ public function test_is_javascript_script_tag_returns_false_before_finding_tags( $this->assertFalse( $processor->is_javascript_script_tag(), - 'Should return false when no tag has been selected' + 'Should return false when not stopped on script tag' ); } @@ -154,6 +155,7 @@ public function test_is_json_script_tag( string $html, bool $expected_result ) { $processor = new WP_HTML_Tag_Processor( $html ); $processor->next_tag(); + $this->assertSame( 'SCRIPT', $processor->get_tag(), 'Should be positioned on a SCRIPT tag' ); $this->assertSame( $expected_result, $processor->is_json_script_tag(), @@ -219,7 +221,7 @@ public function test_is_json_script_tag_returns_false_before_finding_tags() { $this->assertFalse( $processor->is_json_script_tag(), - 'Should return false when no tag has been selected' + 'Should return false when not stopped on script tag' ); } From 638925acd80afd9cca8fbc53e717f5fb755df049 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Dec 2025 10:20:47 +0000 Subject: [PATCH 7/8] Update ticket references to 64419 and remove empty line Co-authored-by: sirreal <841763+sirreal@users.noreply.github.com> --- .../tests/html-api/wpHtmlTagProcessorScriptTag.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php index 852a280b800be..b305844c07b18 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php @@ -10,9 +10,8 @@ * @coversDefaultClass WP_HTML_Tag_Processor */ class Tests_HtmlApi_WpHtmlTagProcessorScriptTag extends WP_UnitTestCase { - /** - * @ticket TBD + * @ticket 64419 * * @covers WP_HTML_Tag_Processor::is_javascript_script_tag * @@ -112,7 +111,7 @@ public static function data_is_javascript_script_tag() { } /** - * @ticket TBD + * @ticket 64419 * * @covers WP_HTML_Tag_Processor::is_javascript_script_tag */ @@ -127,7 +126,7 @@ public function test_is_javascript_script_tag_returns_false_before_finding_tags( } /** - * @ticket TBD + * @ticket 64419 * * @covers WP_HTML_Tag_Processor::is_javascript_script_tag */ @@ -142,7 +141,7 @@ public function test_is_javascript_script_tag_returns_false_for_non_html_namespa } /** - * @ticket TBD + * @ticket 64419 * * @covers WP_HTML_Tag_Processor::is_json_script_tag * @@ -211,7 +210,7 @@ public static function data_is_json_script_tag() { } /** - * @ticket TBD + * @ticket 64419 * * @covers WP_HTML_Tag_Processor::is_json_script_tag */ @@ -226,7 +225,7 @@ public function test_is_json_script_tag_returns_false_before_finding_tags() { } /** - * @ticket TBD + * @ticket 64419 * * @covers WP_HTML_Tag_Processor::is_json_script_tag */ From 6d34c8a9ed4627d8ba989ad447f4cf45d7f1d55a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Dec 2025 11:23:15 +0000 Subject: [PATCH 8/8] Add test cases for falsy non-empty string values Co-authored-by: sirreal <841763+sirreal@users.noreply.github.com> --- .../tests/html-api/wpHtmlTagProcessorScriptTag.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php index b305844c07b18..df74d2f6be50b 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorScriptTag.php @@ -47,10 +47,16 @@ public static function data_is_javascript_script_tag() { 'Script tag with empty type attribute' => array( '', true ), 'Script tag with boolean type attribute' => array( '', true ), + // Script tags with falsy but non-empty type attribute. + 'Script tag with type="0"' => array( '', false ), + // Script tags without type but with language attribute - should be JavaScript. 'Script tag with empty language attribute' => array( '', true ), 'Script tag with boolean language attribute' => array( '', true ), + // Script tags with falsy but non-empty language attribute. + 'Script tag with language="0"' => array( '', false ), + // Script tags with JavaScript MIME types - should be JavaScript. 'Script tag with application/ecmascript' => array( '', true ), 'Script tag with application/javascript' => array( '', true ), @@ -197,6 +203,10 @@ public static function data_is_json_script_tag() { 'Script tag without type attribute' => array( '', false ), 'Script tag with empty type attribute' => array( '', false ), 'Script tag with boolean type attribute' => array( '', false ), + + // Script tags with falsy but non-empty type attribute. + 'Script tag with type="0"' => array( '', false ), + 'Script tag with text/javascript type' => array( '', false ), 'Script tag with module type' => array( '', false ), 'Script tag with unknown MIME type' => array( '', false ),