Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of nulls passed via context #46

Merged
merged 1 commit into from
Sep 18, 2024
Merged
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
9 changes: 2 additions & 7 deletions src/main/java/com/dashjoin/jsonata/Jsonata.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Object _evaluate(Symbol expr, Object input, Frame environment) {
result = evaluateRegex(expr); //, input, environment);
break;
case "function":
result = /* await */ evaluateFunction(expr, input, environment, null);
result = /* await */ evaluateFunction(expr, input, environment, Utils.NONE);
break;
case "variable":
result = evaluateVariable(expr, input, environment);
Expand Down Expand Up @@ -1514,11 +1514,6 @@ static Symbol chainAST() {

var lhs = /* await */ evaluate(expr.lhs, input, environment);

// Map null to NULL_VALUE before applying to functions
// TODO: fix more generically!
if (lhs==null)
lhs = Jsonata.NULL_VALUE;

if(expr.rhs.type.equals("function")) {
//Symbol applyTo = new Symbol(); applyTo.context = lhs;
// this is a Object _invocation_; invoke it with lhs expression as the first argument
Expand Down Expand Up @@ -1608,7 +1603,7 @@ Jsonata getPerThreadInstance() {

List<Object> evaluatedArgs = new ArrayList();

if (applytoContext != null) {
if (applytoContext != Utils.NONE) {
evaluatedArgs.add(applytoContext);
}
// eager evaluation - evaluate the arguments
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/dashjoin/jsonata/StringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public void escapeTest() {
public void splitTest() {
Object res;

// Splitting on an undefined value
res = jsonata("$split(a, '-')").evaluate(Map.of());
Assertions.assertNull(res);

// Splitting on an undefined value, equivalent to above
res = jsonata("a ~> $split('-')").evaluate(Map.of());
Assertions.assertNull(res);

// Splitting empty string with empty separator must return empty list
res = jsonata("$split('', '')").evaluate(null);
Assertions.assertEquals(Arrays.asList(), res);
Expand Down
Loading