Repository navigation
Conversation
jsonata-js returns undefined from $match when its str argument is undefined and the pattern is a regex. JSONata4Java threw "Argument 1 of function $match does not match function signature" instead. Co-Authored-By: Claude Code Signed-off-by: Jan Nedbal <jan.nedbal@shipmonk.com>
jsonata-js rejects a non-number limit (T0410, argument 3) also when str is undefined. A negative limit still returns undefined, because jsonata-js returns before it checks the limit value. Co-Authored-By: Claude Code Signed-off-by: Jan Nedbal <jan.nedbal@shipmonk.com>
jsonata-js applies the pattern to an empty string like to any other
string. For example, $match("", /^$/) returns one match at index 0.
JSONata4Java threw an argument 1 error instead.
Co-Authored-By: Claude Code
Signed-off-by: Jan Nedbal <jan.nedbal@shipmonk.com>
jsonata-js returns an empty sequence (undefined) when the pattern does
not match. JSONata4Java returned []. A limit of 0 already returned
undefined.
The existing test for $match('ababbabbcc','a(b+)') expected []. It
checks that a string pattern matches literally, so it now expects
undefined.
Co-Authored-By: Claude Code
Signed-off-by: Jan Nedbal <jan.nedbal@shipmonk.com>
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.
This PR aligns
$matchwith jsonata-js for undefined, empty and non-matching input. The results below use jsonata-js 2.2.2 and JSONata4Java master. The input can be any value, e.g.{}.1. Undefined
str$match(nothing, /b/)undefinedArgument 1 of function $match does not match function signature$match($substringAfter(nothing, "x"), /b/).groups[0]undefined$match(nothing, /b/, -1)undefined$match(nothing, /b/, "x")2. Empty
str$match("", /^$/){"match":"","index":0,"groups":[]}Argument 1 of function $match does not match function signature$match("", /b/)undefined3. No match
$match("abc", /z/)undefined[]{"m": $match("abc", /z/)}{}{"m":[]}$exists($match("abc", /z/))falsetrueReferences
match()insrc/functions.jsreturns undefined first whenstris undefined ("undefined inputs always return undefined"). It checks the limit value only after that. Signature validation still rejects a non-number limit.this.createSequence(), which is undefined when nothing matches.docs/regex.mdsays that when nothing is matched, the result is "the empty sequence (i.e. JavaScriptundefined)".docs/simple.mdsays "No errors are thrown as a result of non-existing data in the input document."$split,$replaceand$matchshare the docs wording "It is an error ifstris not a string". The test-suite casesfunction-split/case010,function-replace/case004andfunction-contains/case004expect undefined fornothing. JSONata4Java already returns undefined for those functions.Related to #291. That issue shows the same error message for
$match($.a, /(\d+)/), but its cause was the context-variable logic. Its repro already passes on master.Fix
The fix is in
MatchFunction, one commit per behavior:stris undefined and the pattern is a regex, return undefined. A limit that is not a number still gives the argument 3 error.str.String patterns are a JSONata4Java extension, and jsonata-js rejects them.
$match(nothing, 'b')still throws. A string pattern that does not match now also returns undefined, because both pattern kinds share the result code.Changed existing test:
$match('ababbabbcc','a(b+)')expected[]. It checks that a string pattern matches literally. It now expects undefined. The equivalent jsonata-js expression$match("ababbabbcc", /a\(b\+\)/)also returns undefined.Tests
I added these cases to
MatchFunctionTests. The expected values come from jsonata-js 2.2.2:str:$match(a.b.c, /b/),$match(a.b.c, /b/, 1),$match(a.b.c, /b/, -1),$match($substringAfter(a.b.c, 'x'), /(b)/).groups[0], plus the argument 3 errors for'x'andnullstr:$match('', /^$/),$match('', /(x*)/),$match('', /b/)$match('abc', /z/),$match('abc', /z/, 1)The default surefire includes (
**/*Test.class) do not select*Testsclasses. So I ran two commands on JDK 17:mvn verify: 1223 tests, 0 failures. Master gives the same result.mvn test -Dtest='com/api/jsonata4java/**/*Tests': 1977 tests, 0 failures. Master runs 1966 tests with 0 failures.Co-Authored-By: Claude Code
— Claude