From 9be5ebb59aee29d605fae13590921a0031f8fa34 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 12:36:58 +0000 Subject: [PATCH 1/4] Initial plan From df9d7444a032b620742ac6345a6f51fdc8283f62 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 12:45:45 +0000 Subject: [PATCH 2/4] Add TEXTAREA tests for \r and \r\n newline variants Co-authored-by: sirreal <841763+sirreal@users.noreply.github.com> --- .../html-api/wpHtmlProcessorModifiableText.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index 40627b76fa5e1..4d4350ae30ed9 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -190,5 +190,22 @@ public static function data_modifiable_text_special_leading_whitespace() { "<{$tag_name}>", ); } + + // TEXTAREA tests - similar to PRE and LISTING elements. + yield 'TEXTAREA insert with leading carriage return' => array( + '', + 1, + 'REPLACEME', + "\rCR", + "", + ); + + yield 'TEXTAREA insert with leading carriage return + newline' => array( + '', + 1, + 'REPLACEME', + "\r\nCR-N", + "", + ); } } From 4293b890b5cf7a2f96bb3f280e456b7b01b8b202 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 12:49:09 +0000 Subject: [PATCH 3/4] Add TEXTAREA tests for \r and \r\n newline variants Co-authored-by: sirreal <841763+sirreal@users.noreply.github.com> --- .../wpHtmlProcessorModifiableText.php | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index 4d4350ae30ed9..f77eb39b17948 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -27,6 +27,44 @@ public function test_modifiable_text_special_textarea() { ); } + /** + * TEXTAREA elements ignore the first newline in their content. + * Setting the modifiable text with a leading carriage return should be normalized + * and ensure the leading newline is present in the resulting TEXTAREA. + * + * @ticket 64607 + */ + public function test_modifiable_text_special_textarea_carriage_return() { + $processor = WP_HTML_Processor::create_fragment( '' ); + $processor->next_token(); + $processor->set_modifiable_text( "\rCR" ); + // Newline normalization transforms \r into \n, and special handling should preserve it. + $this->assertSame( + "\nCR", + $processor->get_modifiable_text(), + 'Should have normalized carriage return and preserved the leading newline in the TEXTAREA content.' + ); + } + + /** + * TEXTAREA elements ignore the first newline in their content. + * Setting the modifiable text with a leading carriage return + newline should be normalized + * and ensure the leading newline is present in the resulting TEXTAREA. + * + * @ticket 64607 + */ + public function test_modifiable_text_special_textarea_carriage_return_newline() { + $processor = WP_HTML_Processor::create_fragment( '' ); + $processor->next_token(); + $processor->set_modifiable_text( "\r\nCR-N" ); + // Newline normalization transforms \r\n into \n, and special handling should preserve it. + $this->assertSame( + "\nCR-N", + $processor->get_modifiable_text(), + 'Should have normalized carriage return + newline and preserved the leading newline in the TEXTAREA content.' + ); + } + /** * PRE and LISTING elements ignore the first newline in their content. * Setting the modifiable text with a leading newline should ensure that the leading newline @@ -190,22 +228,5 @@ public static function data_modifiable_text_special_leading_whitespace() { "<{$tag_name}>", ); } - - // TEXTAREA tests - similar to PRE and LISTING elements. - yield 'TEXTAREA insert with leading carriage return' => array( - '', - 1, - 'REPLACEME', - "\rCR", - "", - ); - - yield 'TEXTAREA insert with leading carriage return + newline' => array( - '', - 1, - 'REPLACEME', - "\r\nCR-N", - "", - ); } } From 32e667fbb73039622b6a215eee2b85ce2610bcd3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 13:04:06 +0000 Subject: [PATCH 4/4] Add assertEqualHTML to TEXTAREA tests and update ticket to 64609 Co-authored-by: sirreal <841763+sirreal@users.noreply.github.com> --- .../html-api/wpHtmlProcessorModifiableText.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index f77eb39b17948..a73137a21e3d5 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -32,7 +32,7 @@ public function test_modifiable_text_special_textarea() { * Setting the modifiable text with a leading carriage return should be normalized * and ensure the leading newline is present in the resulting TEXTAREA. * - * @ticket 64607 + * @ticket 64609 */ public function test_modifiable_text_special_textarea_carriage_return() { $processor = WP_HTML_Processor::create_fragment( '' ); @@ -44,6 +44,12 @@ public function test_modifiable_text_special_textarea_carriage_return() { $processor->get_modifiable_text(), 'Should have normalized carriage return and preserved the leading newline in the TEXTAREA content.' ); + $this->assertEqualHTML( + "", + $processor->get_updated_html(), + '', + 'Should have doubled the newline in the output HTML to preserve the leading newline.' + ); } /** @@ -51,7 +57,7 @@ public function test_modifiable_text_special_textarea_carriage_return() { * Setting the modifiable text with a leading carriage return + newline should be normalized * and ensure the leading newline is present in the resulting TEXTAREA. * - * @ticket 64607 + * @ticket 64609 */ public function test_modifiable_text_special_textarea_carriage_return_newline() { $processor = WP_HTML_Processor::create_fragment( '' ); @@ -63,6 +69,12 @@ public function test_modifiable_text_special_textarea_carriage_return_newline() $processor->get_modifiable_text(), 'Should have normalized carriage return + newline and preserved the leading newline in the TEXTAREA content.' ); + $this->assertEqualHTML( + "", + $processor->get_updated_html(), + '', + 'Should have doubled the newline in the output HTML to preserve the leading newline.' + ); } /**