Skip to content

Commit

Permalink
$eval() - array inputs should be wrapped
Browse files Browse the repository at this point in the history
The logic for handling the second parameter to this function should be the same as for handling the input to any expression.
This includes wrapping a top level array input in a singleton sequence so it gets treated as a single input.
This code was missing from this function and is added here.

Signed-off-by: andrew-coleman <[email protected]>
  • Loading branch information
andrew-coleman authored and mattbaileyuk committed Oct 23, 2020
1 parent 27724d9 commit ca3070f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/jsonata.js
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,11 @@ var jsonata = (function() {
var input = this.input;
if(typeof focus !== 'undefined') {
input = focus;
// if the input is a JSON array, then wrap it in a singleton sequence so it gets treated as a single input
if(Array.isArray(input) && !isSequence(input)) {
input = createSequence(input);
input.outerWrapper = true;
}
}

try {
Expand Down
34 changes: 34 additions & 0 deletions test/test-suite/groups/function-eval/case008.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"expr": "$eval(\"{ 'test': 1 }\", [])",
"data": {},
"bindings": {},
"result": {
"test": 1
}
},
{
"expr": "$eval(\"{ 'test': 1 }\")",
"data": [],
"bindings": {},
"result": {
"test": 1
}
},
{
"expr": "$eval(\"{ 'test': 1 }\", [1,2,3])",
"data": [],
"bindings": {},
"result": {
"test": 1
}
},
{
"expr": "$eval(\"{ 'test': 1 }\")",
"data": [1,2,3],
"bindings": {},
"result": {
"test": 1
}
}
]

0 comments on commit ca3070f

Please sign in to comment.