Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/main/java/com/dashjoin/jsonata/utils/Signature.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public Object validate(Object _args, Object context) {
for (Object _param : _params) {
Param param = (Param)_param;
var arg = argIndex<args.size() ? args.get(argIndex) : null;
String match = isValid.group(index + 1);
String match = isValid.group(index++ + 1);
if ("".equals(match)) {
if (param.context && param.regex!=null) {
// substitute context value for missing arg
Expand Down Expand Up @@ -391,10 +391,9 @@ public Object validate(Object _args, Object context) {
}
}
}
index++;
}
return validatedArgs;
}
}
throwValidationError(args, suppliedSig, functionName);
return null; // dead code -> compiler happy
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/dashjoin/jsonata/DateTimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public void testToMillis() {
Jsonata expr = Jsonata.jsonata("$fromMillis($toMillis($))");
String timestamp = (String) expr.evaluate(noZoneTooPrecise);
Assertions.assertTrue(timestamp.startsWith("2024-08-2"));
Assertions.assertTrue(timestamp.endsWith(":43:15.781Z"));
Assertions.assertTrue(timestamp.endsWith("3:15.781Z"));
}
}
15 changes: 15 additions & 0 deletions src/test/java/com/dashjoin/jsonata/SignatureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ public Object call(Object input, List args) throws Throwable {
Assertions.assertEquals(6, expression.evaluate(null));
}

/**
* Verifies that parameter index tracking works correctly in signature validation.
* Without the index++ fix in Signature.validate(), the second parameter's capture group
* is read at the wrong position, causing valid calls to fail with T0410.
*/
@Test
public void testArrayFirstArgWithFunctionSecondArg() {
// $map has signature <af> : first arg = array, second arg = function
// Without index++ fix, the function arg is validated against group(1) instead of group(2)
var expression = jsonata("$map([1,2,3], function($v) { $v * 2 })");
var result = expression.evaluate(null);
Assertions.assertNotNull(result);
Assertions.assertEquals(java.util.List.of(2, 4, 6), result);
}

@Test
public void testVarArgMany(){
Jsonata expr = jsonata("$customArgs('test',[1,2,3,4],3)");
Expand Down