fix: exact field-key match in trigger_display_if to prevent false positives - #898
Open
thisismyurl wants to merge 1 commit into
Open
Conversation
…itives
The previous name.match(displaySrc) call treated displaySrc as a regex
and did a substring search against the trigger input's full HTML name
attribute (e.g. custom_meta_group[meta]). This caused display_if to fire
for unrelated triggers whenever displaySrc appeared as a substring of the
group name or another field name.
Replace the partial match with an exact-key check:
- name === displaySrc (top-level fields with no bracket wrapping)
- name.indexOf('[' + displaySrc + ']') !== -1 (nested fields)
This ensures only the field whose key exactly matches display-src can
trigger visibility changes.
Fixes alleyinteractive#873
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the “display-if” field matching logic in the FieldManager initializer to use explicit string comparisons rather than regex matching.
Changes:
- Replaces
name.match(...)regex-based matching with exact-match and bracketed-substring matching. - Caches
display-srcin a local variable to avoid repeated jQuery data lookups.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+299
to
+300
| var displaySrc = $( this ).data( 'display-src' ); | ||
| if ( name && ( name === displaySrc || name.indexOf( '[' + displaySrc + ']' ) !== -1 ) ) { |
Comment on lines
+299
to
+300
| var displaySrc = $( this ).data( 'display-src' ); | ||
| if ( name && ( name === displaySrc || name.indexOf( '[' + displaySrc + ']' ) !== -1 ) ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
trigger_display_ifusedname.match( displaySrc )to decide whether achanged input should trigger visibility changes on
display_ifsiblings.String.prototype.match()treats its argument as a regex and matchessubstrings, so any trigger input whose full HTML
nameattribute containsdisplaySrcas a substring incorrectly fires the display logic.Reproducer (from #873)
When
subject_prefixchanges, its input name iscustom_meta_group[subject_prefix]. The old code evaluates:…because
"meta"is a substring of"custom_meta_group". This causestext_fieldto be shown or hidden wheneversubject_prefixchanges,even though
text_fieldshould only react tometa.Fix
Replace the partial regex match with an exact bracket-key check:
name === displaySrchandles top-level Fieldmanager fields whoseinput name is the bare field key (no bracket notation).
name.indexOf( '[' + displaySrc + ']' ) !== -1handles nested fieldswhere the key is wrapped in brackets (e.g.
group[meta]). Thesurrounding brackets ensure
[meta]cannot match[meta_info]or[custom_meta_group].Testing
subject_prefix— confirmtext_fieldvisibility does not change.metacheckbox — confirmtext_fieldshows/hides correctly.npm test(or equivalent).Fixes #873
Development and testing assisted by AI. All code reviewed and verified manually.