Skip to content

[6.x] Match contains_any values literally in field conditions - #15531

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
joshdaugherty:fix/field-conditions-contains-any-literal
Sep 29, 2026
Merged

jasonvarga merged 1 commit into
statamic:6.xfrom
joshdaugherty:fix/field-conditions-contains-any-literal

Conversation

@joshdaugherty

Copy link
Copy Markdown
Contributor

Fixes #15530

contains_any built a regular expression from its values without escaping them, so a.b matched axb, (555) matched any value containing 555, $100 never matched, and C++ threw SyntaxError: Invalid regular expression.

This matches each value as a literal substring instead, which keeps the operator's substring semantics (contains_any foo still matches foobar) without reading any value as a pattern. A null or undefined field value is now treated as an empty string. Before, RegExp.prototype.test coerced it to the text "null" or "undefined", so contains_any ul matched an empty field. The array branch is unchanged: it already compares values exactly through intersection.

includes_any is not touched; #13135 already gave it exact matching.

Tests

Adds it matches contains_any values literally rather than as patterns to resources/js/tests/FieldConditionsValidator.test.js, covering ., (…), + and $. It fails on 6.x without the change (axb matches a.b) and passes with it; the file's other 52 tests still pass, and npx vitest run --project unit passes (628 tests).

@joshdaugherty joshdaugherty changed the title Match contains_any values literally in field conditions [6.x] Match contains_any values literally in field conditions Sep 29, 2026
@jasonvarga
jasonvarga merged commit 7140f87 into statamic:6.x Sep 29, 2026
62 of 63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

contains_any field conditions treat values as a regular expression

2 participants