Skip to content

Commit 5f2be9e

Browse files
committed
Interactivity API: fix data-wp-bind skipping valid directives after encountering an invalid one
Change `return` to `continue` in `data_wp_bind_processor` so that when an element has multiple `data-wp-bind` directives and one is invalid (empty suffix or unique ID), the invalid entry is skipped instead of causing the entire function to exit, allowing valid directives on the same element to still be processed. Props DAreRodz, ozgursar, alexodiy. Fixes #64518. git-svn-id: https://develop.svn.wordpress.org/trunk@62070 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 657b6ff commit 5f2be9e

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/wp-includes/interactivity-api/class-wp-interactivity-api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ private function data_wp_bind_processor( WP_Interactivity_API_Directives_Process
10261026
$entries = $this->get_directive_entries( $p, 'bind' );
10271027
foreach ( $entries as $entry ) {
10281028
if ( empty( $entry['suffix'] ) || null !== $entry['unique_id'] ) {
1029-
return;
1029+
continue;
10301030
}
10311031

10321032
// Skip if the suffix is an event handler.

tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-bind.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ public function test_wp_bind_ignores_empty_bound_attribute() {
134134
$this->assertSame( $html, $new_html );
135135
}
136136

137+
/**
138+
* Tests that `data-wp-bind` ignores directives with no suffix but still
139+
* processes valid bind directives on the same element.
140+
*
141+
* @ticket 64518
142+
*
143+
* @covers ::process_directives
144+
*/
145+
public function test_wp_bind_ignores_empty_suffix_but_processes_valid_binds() {
146+
$html = '<div data-wp-bind="myPlugin::state.id" data-wp-bind--id="myPlugin::state.id">Text</div>';
147+
list($p) = $this->process_directives( $html );
148+
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
149+
}
150+
137151
/**
138152
* Tests that `data-wp-bind` does nothing when referencing non-existent
139153
* references.
@@ -416,4 +430,18 @@ public function test_wp_bind_ignores_unique_ids() {
416430
$this->assertNull( $p->get_attribute( 'id' ) );
417431
$this->assertNull( $p->get_attribute( 'id---unique-id' ) );
418432
}
433+
434+
/**
435+
* Tests that `data-wp-bind` ignores directives with unique IDs but still
436+
* processes valid bind directives on the same element.
437+
*
438+
* @ticket 64518
439+
*
440+
* @covers ::process_directives
441+
*/
442+
public function test_wp_bind_ignores_unique_id_but_processes_valid_binds() {
443+
$html = '<div data-wp-bind--id---unique-id="myPlugin::state.id" data-wp-bind--id="myPlugin::state.id">Text</div>';
444+
list($p) = $this->process_directives( $html );
445+
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
446+
}
419447
}

0 commit comments

Comments
 (0)