From 3082fd25ac57716385b1530275f3ae5018edeaa0 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Mon, 11 Mar 2024 13:02:57 +0100 Subject: [PATCH 1/3] Add test for iframe --- ...pi.php => wpInteractivityAPIFunctions.php} | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) rename tests/phpunit/tests/interactivity-api/{interactivity-api.php => wpInteractivityAPIFunctions.php} (92%) diff --git a/tests/phpunit/tests/interactivity-api/interactivity-api.php b/tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php similarity index 92% rename from tests/phpunit/tests/interactivity-api/interactivity-api.php rename to tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php index 7d74fda8eb44..3a08a2f1af57 100644 --- a/tests/phpunit/tests/interactivity-api/interactivity-api.php +++ b/tests/phpunit/tests/interactivity-api/wpInteractivityAPIFunctions.php @@ -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. */ @@ -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 ''; + }, + 'supports' => array( + 'interactivity' => true, + ), + ) + ); + $post_content = ''; + $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' ) ); + } } From 3af803a3803858b19b4017f005003227e81f40b1 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Mon, 11 Mar 2024 13:03:15 +0100 Subject: [PATCH 2/3] 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 9e5b1be1fa5e..a36f04c2c958 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 ); } From f2dd8b64448cb670665e4b1b8bc417343f7db435 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Mon, 11 Mar 2024 15:48:40 +0100 Subject: [PATCH 3/3] Fix comment spacing --- .../interactivity-api/class-wp-interactivity-api.php | 6 +++--- 1 file changed, 3 insertions(+), 3 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 a36f04c2c958..22c196184b30 100644 --- a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php +++ b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php @@ -283,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 ); }