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 0cdcd4cd85531..e868ffe9e89ab 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
@@ -1556,24 +1556,33 @@ private function skip_script_data(): bool {
}
/*
- * Unlike with "-->", the "" or "".
+ *
+ * Note that this check may advance the position significantly and requires a
+ * length check to prevent bad offsets on inputs like `', true ),
- 'Script with type attribute' => array( '', true ),
- 'Script data escaped' => array( '', true ),
- 'Script data double-escaped exit (comment)' => array( '', true ),
- 'Script data double-escaped exit (closed)' => array( '', true ),
- 'Script data double-escaped exit (closed/truncated)' => array( '', true ),
- 'Script data no double-escape' => array( '', true ),
-
- 'Script tag with self-close flag (ignored)' => array( '', false ),
- 'Script data double-escaped' => array( '', false ),
- );
+ public static function data_script_tag(): Generator {
+
+ yield 'Basic script tag' => array( '', true );
+ yield 'Script with type attribute' => array( '', true );
+ yield 'Script data escaped' => array( '', true );
+ yield 'Script data double-escaped exit (comment)' => array( '', true );
+ yield 'Script data double-escaped exit (closed)' => array( '', true );
+ yield 'Script data double-escaped exit (closed/truncated)' =>
+ array( '', true );
+ yield 'Script data no double-escape' => array( '', true );
+ yield 'Script data no double-escape (short comment)' => array( '', true );
+ yield 'Script data almost double-escaped' => array( '', true );
+ yield 'Script data with complex JavaScript' => array(
+ '',
+ true,
+ );
+
+ yield 'Script tag with self-close flag (ignored)' => array( '', false );
+ yield 'Script data double-escaped' => array( '', false );
+ yield 'Unclosed script in escaped state' => array( ' array( '