HTML API: Preserve ::set_modifiable_text() TEXTAREA leading newlines.

HTML specifies that a single newline is ignored at the start of a `TEXTAREA`. If `::set_modifiable_text()` is called with a leading newline, ensure it is preserved in the resulting HTML.

Developed in https://github.com/WordPress/wordpress-develop/pull/11062.

Props jonsurrell, dmsnell.
See #64609.

Built from https://develop.svn.wordpress.org/trunk@61754


git-svn-id: http://core.svn.wordpress.org/trunk@61060 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
jonsurrell
2026-02-27 12:56:45 +00:00
parent dded7c75e6
commit 9e1e6914e7
2 changed files with 12 additions and 1 deletions

View File

@@ -3877,6 +3877,17 @@ class WP_HTML_Tag_Processor {
$plaintext_content
);
/*
* HTML ignores a single leading newline in this context. If a leading newline
* is intended, preserve it by adding an extra newline.
*/
if (
'TEXTAREA' === $this->get_tag() &&
1 === strspn( $plaintext_content, "\n\r", 0, 1 )
) {
$plaintext_content = "\n{$plaintext_content}";
}
/*
* These don't _need_ to be escaped, but since they are decoded it's
* safe to leave them escaped and this can prevent other code from

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '7.0-beta2-61753';
$wp_version = '7.0-beta2-61754';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.