From d11ebcecdd60b1c9cfd5ab68f1f4e0f393ce52cd Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Tue, 12 Mar 2024 08:40:23 +0100 Subject: [PATCH] Fix tags with closing tag not visited --- .../class-wp-interactivity-api.php | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php index 9e5b1be1fa5ed..a36f04c2c958b 100644 --- a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php +++ b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php @@ -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' ) ) ) { @@ -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 ); }