Skip to content

Commit b66dceb

Browse files
committed
HTML API: Fix void tag nesting with next_token
When `next_token()` was introduced, it introduced a regression in the HTML Processor whereby void tags remain on the stack of open elements when they shouldn't. This led to invalid values returned from `get_breadcrumbs()`. The reason was that calling `next_token()` works through a different code path than the HTML Processor runs everything else. To solve this, its sub-classed `next_token()` called `step( self::REPROCESS_CURRENT_TOKEN )` so that the proper HTML accounting takes place. Unfortunately that same reprocessing code path skipped the step whereby void and self-closing elements are popped from the stack of open elements. In this patch, that step is run with a third mode for `step()`, which is the new `self::PROCESS_CURRENT_TOKEN`. This mode acts as if `self::PROCESS_NEXT_NODE` were called, except it doesn't advance the parser. Developed in WordPress/wordpress-develop#5975 Discussed in https://core.trac.wordpress.org/ticket/60382 Follow-up to [57348] Props dmsnell, jonsurrell Fixes #60382 Built from https://develop.svn.wordpress.org/trunk@57507 git-svn-id: https://core.svn.wordpress.org/trunk@57008 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 5f09f49 commit b66dceb

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

wp-includes/html-api/class-wp-html-processor.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public function next_token() {
431431
$found_a_token = parent::next_token();
432432

433433
if ( '#tag' === $this->get_token_type() ) {
434-
$this->step( self::REPROCESS_CURRENT_NODE );
434+
$this->step( self::PROCESS_CURRENT_NODE );
435435
}
436436

437437
return $found_a_token;
@@ -513,7 +513,7 @@ public function step( $node_to_process = self::PROCESS_NEXT_NODE ) {
513513
return false;
514514
}
515515

516-
if ( self::PROCESS_NEXT_NODE === $node_to_process ) {
516+
if ( self::REPROCESS_CURRENT_NODE !== $node_to_process ) {
517517
/*
518518
* Void elements still hop onto the stack of open elements even though
519519
* there's no corresponding closing tag. This is important for managing
@@ -532,7 +532,9 @@ public function step( $node_to_process = self::PROCESS_NEXT_NODE ) {
532532
if ( $top_node && self::is_void( $top_node->node_name ) ) {
533533
$this->state->stack_of_open_elements->pop();
534534
}
535+
}
535536

537+
if ( self::PROCESS_NEXT_NODE === $node_to_process ) {
536538
while ( parent::next_token() && '#tag' !== $this->get_token_type() ) {
537539
continue;
538540
}
@@ -1781,6 +1783,15 @@ public static function is_void( $tag_name ) {
17811783
*/
17821784
const REPROCESS_CURRENT_NODE = 'reprocess-current-node';
17831785

1786+
/**
1787+
* Indicates that the current HTML token should be processed without advancing the parser.
1788+
*
1789+
* @since 6.5.0
1790+
*
1791+
* @var string
1792+
*/
1793+
const PROCESS_CURRENT_NODE = 'process-current-node';
1794+
17841795
/**
17851796
* Indicates that the parser encountered unsupported markup and has bailed.
17861797
*

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '6.5-alpha-57506';
19+
$wp_version = '6.5-alpha-57507';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)