Skip to content

Commit 35c4812

Browse files
authored
Merge pull request #46 from rayokota/fix-null-context
Fix handling of nulls passed via context
2 parents abf12e9 + 677e1c5 commit 35c4812

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/main/java/com/dashjoin/jsonata/Jsonata.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Object _evaluate(Symbol expr, Object input, Frame environment) {
188188
result = evaluateRegex(expr); //, input, environment);
189189
break;
190190
case "function":
191-
result = /* await */ evaluateFunction(expr, input, environment, null);
191+
result = /* await */ evaluateFunction(expr, input, environment, Utils.NONE);
192192
break;
193193
case "variable":
194194
result = evaluateVariable(expr, input, environment);
@@ -1514,11 +1514,6 @@ static Symbol chainAST() {
15141514

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

1517-
// Map null to NULL_VALUE before applying to functions
1518-
// TODO: fix more generically!
1519-
if (lhs==null)
1520-
lhs = Jsonata.NULL_VALUE;
1521-
15221517
if(expr.rhs.type.equals("function")) {
15231518
//Symbol applyTo = new Symbol(); applyTo.context = lhs;
15241519
// this is a Object _invocation_; invoke it with lhs expression as the first argument
@@ -1608,7 +1603,7 @@ Jsonata getPerThreadInstance() {
16081603

16091604
List<Object> evaluatedArgs = new ArrayList();
16101605

1611-
if (applytoContext != null) {
1606+
if (applytoContext != Utils.NONE) {
16121607
evaluatedArgs.add(applytoContext);
16131608
}
16141609
// eager evaluation - evaluate the arguments

src/test/java/com/dashjoin/jsonata/StringTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ public void escapeTest() {
7373
public void splitTest() {
7474
Object res;
7575

76+
// Splitting on an undefined value
77+
res = jsonata("$split(a, '-')").evaluate(Map.of());
78+
Assertions.assertNull(res);
79+
80+
// Splitting on an undefined value, equivalent to above
81+
res = jsonata("a ~> $split('-')").evaluate(Map.of());
82+
Assertions.assertNull(res);
83+
7684
// Splitting empty string with empty separator must return empty list
7785
res = jsonata("$split('', '')").evaluate(null);
7886
Assertions.assertEquals(Arrays.asList(), res);

0 commit comments

Comments
 (0)