diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 24bc298da7122..acf884f47738f 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -413,6 +413,23 @@ public function next_tag( $query = null ) { return false; } + /** + * Steps through the HTML document and stop at the next token, if any. + * + * Currently only supports stepping through tags. + * + * @return bool + */ + public function next_token() { + $found_a_token = parent::next_token(); + + if ( '#tag' === $this->get_token_type() ) { + $this->step( self::REPROCESS_CURRENT_NODE ); + } + + return $found_a_token; + } + /** * Indicates if the currently-matched tag matches the given breadcrumbs. * 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 5fd3144f531db..1e56834d4eda6 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 @@ -515,7 +515,7 @@ class WP_HTML_Tag_Processor { * * @var string */ - private $parser_state = self::STATE_READY; + protected $parser_state = self::STATE_READY; /** * How many bytes from the original HTML document have been read and parsed. @@ -2294,7 +2294,7 @@ public function seek( $bookmark_name ) { // Point this tag processor before the sought tag opener and consume it. $this->bytes_already_parsed = $this->bookmarks[ $bookmark_name ]->start; - return $this->next_tag( array( 'tag_closers' => 'visit' ) ); + return $this->next_token(); } /** diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessor-token-scanning.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessor-token-scanning.php index 8cd1dfcac61eb..2f59b430f21c3 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessor-token-scanning.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessor-token-scanning.php @@ -22,7 +22,7 @@ class Tests_HtmlApi_WpHtmlProcessor_Token_Scanning extends WP_UnitTestCase { * @covers WP_HTML_Tag_Processor::next_token */ public function test_completes_empty_document() { - $processor = WP_HTML_Processor::create_fragment( '' ); + $processor = new WP_HTML_Tag_Processor( '' ); $this->assertFalse( $processor->next_token(), @@ -40,7 +40,7 @@ public function test_completes_empty_document() { * @covers WP_HTML_Tag_Processor::next_token */ public function test_basic_assertion_text_node() { - $processor = WP_HTML_Processor::create_fragment( 'Hello, World!' ); + $processor = new WP_HTML_Tag_Processor( 'Hello, World!' ); $processor->next_token(); $this->assertSame( @@ -66,7 +66,7 @@ public function test_basic_assertion_text_node() { * @covers WP_HTML_Tag_Processor::next_token */ public function test_basic_assertion_element() { - $processor = WP_HTML_Processor::create_fragment( '
Hello, World!
' ); + $processor = new WP_HTML_Tag_Processor( '
Hello, World!
' ); $processor->next_token(); $this->assertSame( @@ -111,7 +111,7 @@ public function test_basic_assertion_element() { * @covers WP_HTML_Tag_Processor::next_token */ public function test_basic_assertion_script_element() { - $processor = WP_HTML_Processor::create_fragment( '' ); + $processor = new WP_HTML_Tag_Processor( '' ); $processor->next_token(); $this->assertSame( @@ -151,7 +151,7 @@ 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( + $processor = new WP_HTML_Tag_Processor( << Is > XHTML? @@ -204,7 +204,7 @@ 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( + $processor = new WP_HTML_Tag_Processor( << Is > XHTML? @@ -254,7 +254,7 @@ 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( + $processor = new WP_HTML_Tag_Processor( << Is > XHTML? @@ -315,7 +315,7 @@ public function data_rawtext_elements() { * @covers WP_HTML_Tag_Processor::next_token */ public function test_basic_assertion_cdata_section() { - $processor = WP_HTML_Processor::create_fragment( '' ); + $processor = new WP_HTML_Tag_Processor( '' ); $processor->next_token(); $this->assertSame( @@ -351,7 +351,7 @@ public function test_basic_assertion_cdata_section() { * @covers WP_HTML_Tag_Processor::next_token */ public function test_basic_assertion_abruptly_closed_cdata_section() { - $processor = WP_HTML_Processor::create_fragment( ' a comment]]>' ); + $processor = new WP_HTML_Tag_Processor( ' a comment]]>' ); $processor->next_token(); $this->assertSame( @@ -401,7 +401,7 @@ public function test_basic_assertion_abruptly_closed_cdata_section() { * @covers WP_HTML_Tag_Processor::next_token */ public function test_basic_assertion_processing_instruction() { - $processor = WP_HTML_Processor::create_fragment( '' ); + $processor = new WP_HTML_Tag_Processor( '' ); $processor->next_token(); $this->assertSame( @@ -443,7 +443,7 @@ public function test_basic_assertion_processing_instruction() { * @covers WP_HTML_Tag_Processor::next_token */ public function test_basic_assertion_abruptly_closed_processing_instruction() { - $processor = WP_HTML_Processor::create_fragment( '=5.3.6"?>' ); + $processor = new WP_HTML_Tag_Processor( '=5.3.6"?>' ); $processor->next_token(); $this->assertSame( @@ -498,7 +498,7 @@ public function test_basic_assertion_abruptly_closed_processing_instruction() { * @param string $text Contains the appropriate modifiable text. */ public function test_basic_assertion_common_comments( $html, $text ) { - $processor = WP_HTML_Processor::create_fragment( $html ); + $processor = new WP_HTML_Tag_Processor( $html ); $processor->next_token(); $this->assertSame( @@ -557,7 +557,7 @@ public function data_common_comments() { * @covers WP_HTML_Tag_Processor::next_token */ public function test_basic_assertion_html_comment() { - $processor = WP_HTML_Processor::create_fragment( '' ); + $processor = new WP_HTML_Tag_Processor( '' ); $processor->next_token(); $this->assertSame( @@ -599,7 +599,7 @@ public function test_basic_assertion_html_comment() { * @covers WP_HTML_Tag_Processor::next_token */ public function test_basic_assertion_doctype() { - $processor = WP_HTML_Processor::create_fragment( '' ); + $processor = new WP_HTML_Tag_Processor( '' ); $processor->next_token(); $this->assertSame( @@ -641,7 +641,7 @@ public function test_basic_assertion_doctype() { * @covers WP_HTML_Tag_Processor::next_token */ public function test_basic_assertion_presumptuous_tag() { - $processor = WP_HTML_Processor::create_fragment( '' ); + $processor = new WP_HTML_Tag_Processor( '' ); $processor->next_token(); $this->assertSame( @@ -683,7 +683,7 @@ public function test_basic_assertion_presumptuous_tag() { * @covers WP_HTML_Tag_Processor::next_token */ public function test_basic_assertion_funky_comment() { - $processor = WP_HTML_Processor::create_fragment( '' ); + $processor = new WP_HTML_Tag_Processor( '' ); $processor->next_token(); $this->assertSame(