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 044d1f0c36..0b3dab1ad2 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 @@ -775,7 +775,8 @@ class WP_HTML_Tag_Processor { return false; } - $at += 2; + $closer_potentially_starts_at = $at; + $at += 2; /* * Find a case-insensitive match to the tag name. @@ -818,7 +819,7 @@ class WP_HTML_Tag_Processor { } if ( '>' === $html[ $at ] || '/' === $html[ $at ] ) { - ++$this->bytes_already_parsed; + $this->bytes_already_parsed = $closer_potentially_starts_at; return true; } } @@ -887,7 +888,8 @@ class WP_HTML_Tag_Processor { } if ( '/' === $html[ $at ] ) { - $is_closing = true; + $closer_potentially_starts_at = $at - 1; + $is_closing = true; ++$at; } else { $is_closing = false; @@ -938,7 +940,7 @@ class WP_HTML_Tag_Processor { } if ( $is_closing ) { - $this->bytes_already_parsed = $at; + $this->bytes_already_parsed = $closer_potentially_starts_at; if ( $this->bytes_already_parsed >= $doc_length ) { return false; } @@ -948,7 +950,7 @@ class WP_HTML_Tag_Processor { } if ( '>' === $html[ $this->bytes_already_parsed ] ) { - ++$this->bytes_already_parsed; + $this->bytes_already_parsed = $closer_potentially_starts_at; return true; } } diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php index f0427be01d..d006b3294c 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php @@ -430,6 +430,7 @@ class Tests_HtmlApi_wpHtmlTagProcessor extends WP_UnitTestCase { /** * @ticket 56299 + * @ticket 57852 * * @covers WP_HTML_Tag_Processor::next_tag * @covers WP_HTML_Tag_Processor::is_tag_closer @@ -459,6 +460,45 @@ class Tests_HtmlApi_wpHtmlTagProcessor extends WP_UnitTestCase { 'Did not stop at desired tag closer' ); $this->assertTrue( $p->is_tag_closer(), 'Indicated a tag closer is a tag opener' ); + + $p = new WP_HTML_Tag_Processor( '