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 b2c9db57c169a..4f0f10a1a04f3 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
@@ -3780,17 +3780,28 @@ public function set_modifiable_text( string $plaintext_content ): bool {
switch ( $this->get_tag() ) {
case 'SCRIPT':
- /*
+ /**
* This is over-protective, but ensures the update doesn't break
- * out of the SCRIPT element. A more thorough check would need to
- * ensure that the script closing tag doesn't exist, and isn't
- * also "hidden" inside the script double-escaped state.
+ * the HTML structure of the SCRIPT element.
+ *
+ * More thorough analysis could track the HTML tokenizer states
+ * and to ensure that the SCRIPT element closes at the expected
+ * SCRIPT close tag as is done in {@see ::skip_script_data()}.
*
- * It may seem like replacing ``. A SCRIPT element could be prevented from
+ * closing by contents like `' => array( '', 'Invalid but legitimate comments end in --!>' ),
'SCRIPT with ' => array( '', 'Just a ' ),
'SCRIPT with ' => array( '', 'beforeafter' ),
+ 'SCRIPT with "', '