From b15ad5f3cb9f6ac1f8249d50908d675cb9673204 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Sat, 1 Jun 2024 22:36:37 +0200 Subject: [PATCH] Add diferent message for inner SVG or MATH tags --- ...s-wp-interactivity-api-directives-processor.php | 14 ++++++++++---- .../class-wp-interactivity-api.php | 5 +++++ .../tests/interactivity-api/wpInteractivityAPI.php | 4 ++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php b/src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php index 5d195dd3bd0da..59d8db48fcc69 100644 --- a/src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php +++ b/src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php @@ -201,14 +201,20 @@ public function skip_to_tag_closer(): bool { while ( $depth > 0 && $this->next_tag( array( - 'tag_name' => $tag_name, 'tag_closers' => 'visit', ) ) ) { - if ( $this->has_self_closing_flag() ) { - continue; + if ( ! $this->is_tag_closer() && $this->get_attribute_names_with_prefix( 'data-wp-' ) ) { + /* translators: 1: SVG or MATH HTML tag, 2: Namespace of the interactive block. */ + $message = sprintf( __( 'Interactivity directives were detected inside an incompatible %1$s tag. These directives will be ignored in the server side render.' ), $tag_name ); + _doing_it_wrong( __METHOD__, $message, '6.6.0' ); + } + if ( $this->get_tag() === $tag_name ) { + if ( $this->has_self_closing_flag() ) { + continue; + } + $depth += $this->is_tag_closer() ? -1 : 1; } - $depth += $this->is_tag_closer() ? -1 : 1; } return 0 === $depth; 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 bfdeb74a697fb..ac0ecaf851deb 100644 --- a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php +++ b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php @@ -296,6 +296,11 @@ private function process_directives_args( string $html, array &$context_stack, a * We still process the rest of the HTML. */ if ( 'SVG' === $tag_name || 'MATH' === $tag_name ) { + if ( $p->get_attribute_names_with_prefix( 'data-wp-' ) ) { + /* translators: 1: SVG or MATH HTML tag, 2: Namespace of the interactive block. */ + $message = sprintf( __( 'Interactivity directives were detected on an incompatible %1$s tag when processing "%2$s". These directives will be ignored in the server side render.' ), $tag_name, end( $namespace_stack ) ); + _doing_it_wrong( __METHOD__, $message, '6.6.0' ); + } $p->skip_to_tag_closer(); continue; } diff --git a/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php b/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php index 81825396194e8..5b50978980b8d 100644 --- a/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php +++ b/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php @@ -719,6 +719,7 @@ public function test_process_directives_changes_html_if_contains_svgs() { * @ticket 60517 * * @covers ::process_directives + * @expectedIncorrectUsage WP_Interactivity_API_Directives_Processor::skip_to_tag_closer */ public function test_process_directives_does_not_change_inner_html_in_svgs() { $this->interactivity->state( @@ -748,6 +749,7 @@ public function test_process_directives_does_not_change_inner_html_in_svgs() { * @ticket 60517 * * @covers ::process_directives + * @expectedIncorrectUsage WP_Interactivity_API::process_directives_args */ public function test_process_directives_change_html_if_contains_math() { $this->interactivity->state( @@ -782,6 +784,8 @@ public function test_process_directives_change_html_if_contains_math() { * @ticket 60517 * * @covers ::process_directives + * @expectedIncorrectUsage WP_Interactivity_API::process_directives_args + * @expectedIncorrectUsage WP_Interactivity_API_Directives_Processor::skip_to_tag_closer */ public function test_process_directives_does_not_change_inner_html_in_math() { $this->interactivity->state(