Opened 4 weeks ago
Last modified 4 weeks ago
#64518 new defect (bug)
Interactivity API: `data-wp-bind` stops processing valid directives when encountering an invalid one
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Interactivity API | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
When the Interactivity API is processing the data-wp-bind directive on the server using the data_wp_bind_processor method, a `return` statement inside a `foreach` loop causes the function to exit entirely when encountering a data-wp-bind directive with an empty suffix or a unique ID. This prevents any subsequent valid bind directives on the same element from being processed.
Steps to Reproduce:
- Create an element with both an invalid
data-wp-binddirective (no suffix) and a valid one:
<div
data-wp-interactive="myPlugin"
data-wp-context='{"id":"some-id"}'
data-wp-bind="context.id"
data-wp-bind--id="context.id"
>
Text
</div>
- Process the directives using
wp_interactivity_process_directives().
Expected Behavior:
The invalid data-wp-bind (no suffix) should be skipped, and the valid data-wp-bind--id should be processed, resulting in:
<div
data-wp-interactive="myPlugin"
data-wp-context='{"id":"some-id"}'
data-wp-bind="context.id"
data-wp-bind--id="context.id"
id="some-id"
>
Text
</div>
Actual Behavior:
The return statement exits the function when it encounters the invalid directive, so the valid data-wp-bind--id is never processed. The id attribute is not added.
Change History (1)
This ticket was mentioned in PR #10746 on WordPress/wordpress-develop by @luisherranz.
4 weeks ago
#1
- Keywords has-patch has-unit-tests added
## What
This PR fixes a bug in the
data_wp_bind_processormethod where areturnstatement inside aforeachloop was causing the function to exit entirely when encountering a bind directive with an empty suffix or a unique ID.## Why
When an element has multiple
data-wp-binddirectives, such as:The first directive (
data-wp-bindwith no suffix) is invalid and should be skipped. However, thereturnstatement was causing the entire function to exit, preventing the validdata-wp-bind--iddirective from being processed.## How
Changed
returntocontinueso that invalid entries are skipped while valid entries continue to be processed.---
Trac ticket: https://core.trac.wordpress.org/ticket/64518