Skip to content

Commit

Permalink
regex no longer relies on global state (lastIndex) (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-coleman authored May 23, 2018
1 parent 3c50c69 commit 7cc2b0b
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions jsonata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2349,9 +2349,8 @@ var jsonata = (function() {
* @returns {Function} Higher order function representing prepared regex
*/
function evaluateRegex(expr) {
expr.value.lastIndex = 0;
var re = new RegExp(expr.value);
var closure = function(str) {
var re = expr.value;
var result;
var match = re.exec(str);
if(match !== null) {
Expand All @@ -2371,7 +2370,7 @@ var jsonata = (function() {
return undefined;
} else {
var next = closure(str);
if(next && next.match === '' && re.lastIndex === expr.value.lastIndex) {
if(next && next.match === '') {
// matches zero length string; this will never progress
throw {
code: "D1004",
Expand Down

0 comments on commit 7cc2b0b

Please sign in to comment.