Skip to content
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: 9 additions & 0 deletions src/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,15 @@ const functions = (() => {
if (!Array.isArray(arg2)) {
arg2 = [arg2];
}
const size = arg1.length + arg2.length;
if(this.options && size > this.options.sequence) {
throw {
code: "D2015",
stack: (new Error()).stack,
value: size
};
}

return arg1.concat(arg2);
}

Expand Down
6 changes: 6 additions & 0 deletions src/jsonata.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ var jsonata = (function() {
var result;

var focus = {
options: environment.base.options,
createSequence: environment.base.createSequence
};
switch (expr.value) {
Expand Down Expand Up @@ -600,6 +601,7 @@ var jsonata = (function() {
*/
function evaluateWildcard(expr, input, environment) {
var focus = {
options: environment.base.options,
createSequence: environment.base.createSequence
};
var results = focus.createSequence();
Expand Down Expand Up @@ -913,10 +915,12 @@ var jsonata = (function() {
var groups = Object.create(null);
var reduce = input && input.tupleStream ? true : false;
var focus = {
options: environment.base.options,
createSequence: environment.base.createSequence
};
// group the input sequence by 'key' expression
if (!Array.isArray(input)) {
options: environment.base.options,
input = focus.createSequence(input);
}
// if the array is empty, add an undefined entry to enable literal JSON object to be generated
Expand Down Expand Up @@ -995,6 +999,7 @@ var jsonata = (function() {
}
var result = Object.create(null);
var focus = {
options: environment.base.options,
createSequence: environment.base.createSequence
};
Object.assign(result, tupleStream[0]);
Expand Down Expand Up @@ -1532,6 +1537,7 @@ var jsonata = (function() {
var focus = {
environment: environment,
input: input,
options: environment.base.options,
createSequence: environment.base.createSequence
};
// the `focus` is passed in as the `this` for the invoked function
Expand Down
10 changes: 10 additions & 0 deletions test/implementation-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,16 @@ describe("Tests that include infinite recursion", () => {
code: "D2015",
});
});

it("prevents appending large sequences", function() {
const options = {
'sequence': 1000
}
const expr = jsonata('$append([0..600], [0..600]) ~> $count()', options);
expect(expr.evaluate()).to.eventually.be.rejected.to.deep.contain({
code: "D2015",
});
});
});
});

Expand Down
Loading