Skip to content

Commit

Permalink
Add diferent message for inner SVG or MATH tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cbravobernal committed Jun 1, 2024
1 parent a9f15d8 commit b15ad5f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b15ad5f

Please sign in to comment.