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 4597a888b5efe..26d22c072e48e 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
@@ -926,8 +926,8 @@ private function base_class_next_token() {
return false;
}
$this->parser_state = self::STATE_MATCHED_TAG;
- $this->token_length = $tag_ends_at - $this->token_starts_at;
$this->bytes_already_parsed = $tag_ends_at + 1;
+ $this->token_length = $this->bytes_already_parsed - $this->token_starts_at;
/*
* For non-DATA sections which might contain text that looks like HTML tags but
@@ -1013,7 +1013,7 @@ private function base_class_next_token() {
*/
$this->token_starts_at = $was_at;
$this->token_length = $this->bytes_already_parsed - $this->token_starts_at;
- $this->text_starts_at = $tag_ends_at + 1;
+ $this->text_starts_at = $tag_ends_at;
$this->text_length = $this->tag_name_starts_at - $this->text_starts_at;
$this->tag_name_starts_at = $tag_name_starts_at;
$this->tag_name_length = $tag_name_length;
@@ -2687,7 +2687,7 @@ public function has_self_closing_flag() {
*
', 1, '
' ),
+ 'Void tag w/self-closing flag' => array( '
', 1, '
' ),
+ 'Void tag inside DIV' => array( '
' ),
+
+ // Special atomic tags.
+ 'SCRIPT tag' => array( '', 1, '' ),
+ 'SCRIPT double-escape' => array( '";