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 8a9008f147ac9..43137d386275f 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
@@ -2578,6 +2578,10 @@ public function get_modifiable_text() {
$text = substr( $this->html, $at, $length );
$text = html_entity_decode( $text, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE );
+ if ( empty( $text ) ) {
+ return '';
+ }
+
/*
* PRE and TEXTAREA skip a leading newline, but this newline may not be a `\n`.
* It could be a character reference, such as ``.
diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessor-token-scanning.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessor-token-scanning.php
index b3175734e4b67..f65d0ad0b8fb0 100644
--- a/tests/phpunit/tests/html-api/wpHtmlTagProcessor-token-scanning.php
+++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessor-token-scanning.php
@@ -151,7 +151,8 @@ public function test_basic_assertion_script_element() {
* @covers WP_HTML_Tag_Processor::next_token
*/
public function test_basic_assertion_textarea_element() {
- $processor = WP_HTML_Processor::create_fragment( <<
Is > XHTML?
@@ -203,7 +204,8 @@ public function test_basic_assertion_textarea_element() {
* @covers WP_HTML_Tag_Processor::next_token
*/
public function test_basic_assertion_title_element() {
- $processor = WP_HTML_Processor::create_fragment( <<
Is > XHTML?
@@ -252,7 +254,8 @@ public function test_basic_assertion_title_element() {
* @param string $tag_name The name of the RAWTEXT tag to test.
*/
public function test_basic_assertion_rawtext_elements( $tag_name ) {
- $processor = WP_HTML_Processor::create_fragment( <<
Is > XHTML?
{$tag_name}>