Skip to content

Commit 31d71de

Browse files
committed
Ensure void and self-closing elements pop from stack when advancing.
Previously, the logic to pop void and self-closing elements from the stack of open elements only ran when stepping into the next node in a document. With the introduction of `next_token()` there appeared a new way to reprocesses the current token, so this logic would be skipped when calling `next_token()` _into_ a void or self-closing element, leaving it on the stack. In this patch the logic runs whenever the processor is not reprocessing the current token. A new class constant communicates that `step()` should treat the current token as if it arrived there itself, that is, to process it with the normal rules but without advancing the parser.
1 parent 7890b53 commit 31d71de

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/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
*

0 commit comments

Comments
 (0)