Skip to content

Commit

Permalink
Merge pull request #46 from rayokota/fix-null-context
Browse files Browse the repository at this point in the history
Fix handling of nulls passed via context
  • Loading branch information
aeberhart authored Sep 18, 2024
2 parents abf12e9 + 677e1c5 commit 35c4812
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
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

0 comments on commit 35c4812

Please sign in to comment.