Skip to content

Commit 7a90384

Browse files
authored
Merge pull request #72 from dashjoin/67-positional-variable-binding-broken-if-context-is-null
Positional variable binding broken if context is null. #67
2 parents 4cb3722 + 3338b06 commit 7a90384

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ Frame createFrameFromTuple(Frame environment, Map<String, Object> tuple) {
432432
((JList)result).tupleStream = true;
433433
var stepEnv = environment;
434434
if(tupleBindings == null) {
435-
tupleBindings = (List<Map>) input.stream().filter(item -> item!=null).map(item -> Map.of("@", item)).collect(Collectors.toList());
435+
tupleBindings = (List<Map>) input.stream().map(item -> Utils.mapOf("@", item)).collect(Collectors.toList());
436436
}
437437

438438
for(var ee = 0; ee < tupleBindings.size(); ee++) {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.AbstractList;
2121
import java.util.ArrayList;
2222
import java.util.Collection;
23+
import java.util.HashMap;
2324
import java.util.List;
2425
import java.util.Map;
2526
import java.util.Map.Entry;
@@ -264,5 +265,14 @@ public static void quote(String string, StringBuilder w) {
264265
}
265266
}
266267
}
267-
}
268+
}
269+
270+
/**
271+
* version of Map.of(key, value) that allows value to be null
272+
*/
273+
static Map mapOf(String key, Object value) {
274+
Map<String, Object> map = new HashMap<>();
275+
map.put(key, value);
276+
return map;
277+
}
268278
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public void filterTest() {
2929
Assertions.assertNotNull(expr.evaluate(Map.of("variable", Map.of("field", "1"))));
3030
}
3131

32-
@Disabled
3332
@Test
3433
public void testIndex() {
3534
Jsonata expr = jsonata("($x:=['a','b']; $x#$i.$i)");

0 commit comments

Comments
 (0)