Skip to content

Commit b159c2e

Browse files
fix regression: some instances of divide token were incorrectly parsed as start of regex
1 parent f02405b commit b159c2e

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

jsonata.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ var jsonata = (function() {
800800
advance(',');
801801
}
802802
}
803-
advance(")");
803+
advance(")", true);
804804
// if the name of the function is 'function' or λ, then this is function definition (lambda function)
805805
if (left.type === 'name' && (left.value === 'function' || left.value === '\u03BB')) {
806806
// all of the args must be VARIABLE tokens
@@ -857,7 +857,7 @@ var jsonata = (function() {
857857
}
858858
advance(";");
859859
}
860-
advance(")");
860+
advance(")", true);
861861
this.type = 'block';
862862
this.expressions = expressions;
863863
return this;
@@ -883,7 +883,7 @@ var jsonata = (function() {
883883
advance(",");
884884
}
885885
}
886-
advance("]");
886+
advance("]", true);
887887
this.lhs = a;
888888
this.type = "unary";
889889
return this;
@@ -904,7 +904,7 @@ var jsonata = (function() {
904904
this.lhs = left;
905905
this.rhs = expression(operators[']']);
906906
this.type = 'binary';
907-
advance("]");
907+
advance("]", true);
908908
return this;
909909
}
910910
});
@@ -923,7 +923,7 @@ var jsonata = (function() {
923923
advance(",");
924924
}
925925
}
926-
advance("}");
926+
advance("}", true);
927927
if(typeof left === 'undefined') {
928928
// NUD - unary prefix form
929929
this.lhs = a;
@@ -3304,6 +3304,9 @@ var jsonata = (function() {
33043304
*/
33053305
function lookupMessage(err) {
33063306
var message = 'Unknown error';
3307+
if(typeof err.message !== 'undefined') {
3308+
message = err.message;
3309+
}
33073310
var template = errorCodes[err.code];
33083311
if(typeof template !== 'undefined') {
33093312
// if there are any handlebars, replace them with the field references

test/jsonata-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,15 @@ describe('Evaluator - parenthesis', function () {
660660
});
661661
});
662662

663+
describe('(4 + 2) / 2', function () {
664+
it('should return result object', function () {
665+
var expr = jsonata('(4 + 2) / 2');
666+
var result = expr.evaluate(testdata1);
667+
var expected = 3;
668+
expect(result).to.deep.equal(expected);
669+
});
670+
});
671+
663672
});
664673

665674
describe('Evaluator - simple array selectors', function () {
@@ -2288,6 +2297,15 @@ describe('Evaluator - functions: count', function () {
22882297
expect(result).to.deep.equal(expected);
22892298
});
22902299
});
2300+
2301+
describe('$count([1,2,3,4]) / 2', function () {
2302+
it('should throw an error', function () {
2303+
var expr = jsonata('$count([1,2,3,4]) / 2');
2304+
var result = expr.evaluate();
2305+
var expected = 2;
2306+
expect(result).to.deep.equal(expected);
2307+
});
2308+
});
22912309
});
22922310

22932311
describe('Evaluator - functions: max', function () {

0 commit comments

Comments
 (0)