Skip to content

Fix $contains crash when the token is undefined#809

Open
apoorva-01 wants to merge 1 commit into
jsonata-js:masterfrom
apoorva-01:fix-contains-undefined-token
Open

Fix $contains crash when the token is undefined#809
apoorva-01 wants to merge 1 commit into
jsonata-js:masterfrom
apoorva-01:fix-contains-undefined-token

Conversation

@apoorva-01

@apoorva-01 apoorva-01 commented Jul 2, 2026

Copy link
Copy Markdown

$contains("Hello World", nothing) throws instead of returning undefined. Any time the second arg resolves to undefined it slips past the string check into the regex-matcher branch and calls .apply on undefined. contains already returns undefined when str is undefined, so I just extended that guard to the token too.

Heads up: $split and $replace share the same evaluateMatcher path and blow up the same way ($match is fine, its signature rejects undefined first). I kept this scoped to $contains. If you'd rather squash all three at once, a guard inside evaluateMatcher would do it, but that's a wider change so I left it to you.

Added a test case that goes fail -> pass with the change, full suite green at 100% coverage.

closes #584

Signed-off-by: Apoorva Verma vermaapoorva0510@gmail.com

An undefined second arg fell through to the regex-matcher branch, which
called .apply on it and threw. Return undefined instead, matching the
existing check on str.

Signed-off-by: Apoorva Verma <vermaapoorva0510@gmail.com>
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.

Bug: Accessing undefined property with a function results in an error

1 participant