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
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,18 @@ public JsonNode invoke(ExpressionsVisitor expressionVisitor, Function_callContex
final JsonNode argPattern = FunctionUtils.getValuesListExpression(expressionVisitor, ctx,
useContext ? 0 : 1);
int limit = -1;
// As in jsonata-js, an undefined str with a regex pattern returns undefined
if (argString == null && argPattern instanceof POJONode) {
if (argCount == 3) {
final JsonNode argLimit = FunctionUtils.getValuesListExpression(expressionVisitor, ctx, useContext ? 1 : 2);
if (argLimit != null && !argLimit.isNumber()) {
throw new EvaluateRuntimeException(ERR_ARG3BADTYPE);
}
}
return null;
}
// Make sure that we have the right number of arguments
if (argString == null || !argString.isTextual() || argString.asText().isEmpty()) {
if (argString == null || !argString.isTextual()) {
throw new EvaluateRuntimeException(ERR_ARG1BADTYPE);
}
// Make sure that the pattern is a non-empty string.
Expand Down Expand Up @@ -166,6 +176,10 @@ public JsonNode invoke(ExpressionsVisitor expressionVisitor, Function_callContex
} else {
return null;
}
// As in jsonata-js, no match returns undefined
if (result.size() == 0) {
return null;
}
} else {
// check for a function call context as 2nd parameter
ExprContext exprCtx = ctx.exprValues().exprList().expr(useContext ? 0 : 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,40 @@ public static Collection<Object[]> data() {
{
"$match(' ', a.b.c)", null, ERR_MSG_ARG2_BAD_TYPE
}, //
{
"$match(a.b.c, /b/)", null, null
}, //
{
"$match(a.b.c, /b/, 1)", null, null
}, //
{
"$match(a.b.c, /b/, -1)", null, null
}, //
{
"$match(a.b.c, /b/, 'x')", null, ERR_MSG_ARG3_BAD_TYPE
}, //
{
"$match(a.b.c, /b/, null)", null, ERR_MSG_ARG3_BAD_TYPE
}, //
{
"$match($substringAfter(a.b.c, 'x'), /(b)/).groups[0]", null, null
}, //

{
"$match('', /^$/)", "{\"match\":\"\",\"index\":0,\"groups\":[]}", null
}, //
{
"$match('', /(x*)/)", "{\"match\":\"\",\"index\":0,\"groups\":[\"\"]}", null
}, //
{
"$match('abc', /z/)", null, null
}, //
{
"$match('abc', /z/, 1)", null, null
}, //
{
"$match('', /b/)", null, null
}, //
{
"$match('foo bar', 'a')", "{\"match\":\"a\",\"index\":5,\"groups\":[]}", null
}, //
Expand Down Expand Up @@ -221,7 +254,7 @@ public static Collection<Object[]> data() {
null
},
{
"$match('ababbabbcc','a(b+)')", "[]", null
"$match('ababbabbcc','a(b+)')", null, null
},
{
"$match('aba(b+)babbcc','a(b+)')", "{\"match\":\"a(b+)\",\"index\":2,\"groups\":[]}", null
Expand Down