Skip to content

Commit

Permalink
Fix tags with closing tag not visited
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed Mar 12, 2024
1 parent 155fe30 commit d11ebce
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,22 @@ private function process_directives_args( string $html, array &$context_stack, a
}

if ( $p->is_tag_closer() ) {
list( $opening_tag_name, $directives_prefixes ) = end( $tag_stack );

if ( 0 === count( $tag_stack ) || $opening_tag_name !== $tag_name ) {

/*
* If the tag stack is empty or the matching opening tag is not the
* same than the closing tag, it means the HTML is unbalanced and it
* stops processing it.
*/
$unbalanced = true;
break;
} else {
// Remove the last tag from the stack.
array_pop( $tag_stack );
if ( $p->has_and_visits_its_closer_tag() ) {
list( $opening_tag_name, $directives_prefixes ) = end( $tag_stack );

if ( 0 === count( $tag_stack ) || $opening_tag_name !== $tag_name ) {

/*
* If the tag stack is empty or the matching opening tag is not the
* same than the closing tag, it means the HTML is unbalanced and it
* stops processing it.
*/
$unbalanced = true;
break;
} else {
// Remove the last tag from the stack.
array_pop( $tag_stack );
}
}
} else {
if ( 0 !== count( $p->get_attribute_names_with_prefix( 'data-wp-each-child' ) ) ) {
Expand All @@ -281,9 +283,9 @@ private function process_directives_args( string $html, array &$context_stack, a
}

/*
* If this tag will visit its closer tag, it adds it to the tag stack
* so it can process its closing tag and check for unbalanced tags.
*/
* If this tag will visit its closer tag, it adds it to the tag stack
* so it can process its closing tag and check for unbalanced tags.
*/
if ( $p->has_and_visits_its_closer_tag() ) {
$tag_stack[] = array( $tag_name, $directives_prefixes );
}
Expand Down

0 comments on commit d11ebce

Please sign in to comment.