Skip to content

Commit

Permalink
Merging WordPress#6247: Mario's fix
Browse files Browse the repository at this point in the history
Merge commit 'f2dd8b64448cb670665e4b1b8bc417343f7db435' into interactivity-api/test-dmsnell
  • Loading branch information
dmsnell committed Mar 11, 2024
2 parents e5a7795 + f2dd8b6 commit ac58488
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
30 changes: 16 additions & 14 deletions src/wp-includes/interactivity-api/class-wp-interactivity-api.php
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 Down
Expand Up @@ -10,7 +10,7 @@
*
* @group interactivity-api
*/
class Tests_Interactivity_API_Functions extends WP_UnitTestCase {
class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCase {
/**
* Set up.
*/
Expand Down Expand Up @@ -390,4 +390,31 @@ public function test_wp_interactivity_data_wp_context_with_json_flags() {
$this->assertEquals( 'data-wp-context=\'{"quot":"\u0022baz\u0022"}\'', wp_interactivity_data_wp_context( array( 'quot' => '"baz"' ) ) );
$this->assertEquals( 'data-wp-context=\'{"amp":"T\u0026T"}\'', wp_interactivity_data_wp_context( array( 'amp' => 'T&T' ) ) );
}

/**
* Tests that directives processing of tags that don't visit closer tag work.
*
* @ticket 60746
*
* @covers ::wp_interactivity_process_directives_of_interactive_blocks
*/
public function test_process_directives_in_tags_that_dont_visit_closer_tag() {
register_block_type(
'test/custom-directive-block',
array(
'render_callback' => function () {
return '<iframe data-wp-interactive="nameSpace" ' . wp_interactivity_data_wp_context( array( 'text' => 'test' ) ) . ' data-wp-class--test="context.text" src="1"></iframe>';
},
'supports' => array(
'interactivity' => true,
),
)
);
$post_content = '<!-- wp:test/custom-directive-block /-->';
$processed_content = do_blocks( $post_content );
$processor = new WP_HTML_Tag_Processor( $processed_content );
$processor->next_tag( array( 'class_name' => 'test' ) );
unregister_block_type( 'test/custom-directive-block' );
$this->assertEquals( '1', $processor->get_attribute( 'src' ) );
}
}

0 comments on commit ac58488

Please sign in to comment.