Skip to content

Commit 84ddca6

Browse files
committed
fix for #9
1 parent 2c4341f commit 84ddca6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

processProxy.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ ProcessProxy.prototype._handleCommandFinished = function(command) {
394394

395395
for (var i=0; i<stderrRegExps.length; i++) {
396396
var regexp = stderrRegExps[i];
397+
regexp.lastIndex = 0; // http://blog.geekingfrog.com/reuse-javascript-regexp-global-flag-gotcha/
397398
var result = regexp.exec(stderr);
398399

399400
if (result) {
@@ -410,6 +411,7 @@ ProcessProxy.prototype._handleCommandFinished = function(command) {
410411

411412
for (var i=0; i<stdoutRegExps.length; i++) {
412413
var regexp = stdoutRegExps[i];
414+
regexp.lastIndex = 0; // http://blog.geekingfrog.com/reuse-javascript-regexp-global-flag-gotcha/
413415
var result = regexp.exec(stdout);
414416

415417
if (result) {
@@ -441,6 +443,7 @@ ProcessProxy.prototype._commandIsBlacklisted = function(command) {
441443

442444
for (var i=0; i<this._cmdBlacklistRegexes.length; i++) {
443445
var regexp = this._cmdBlacklistRegexes[i];
446+
regexp.lastIndex = 0; // http://blog.geekingfrog.com/reuse-javascript-regexp-global-flag-gotcha/
444447
var result = regexp.exec(command);
445448

446449
if (result) {
@@ -470,6 +473,7 @@ ProcessProxy.prototype._commandIsWhitelisted = function(command) {
470473

471474
for (var i=0; i<this._cmdWhitelistRegexes.length; i++) {
472475
var regexp = this._cmdWhitelistRegexes[i];
476+
regexp.lastIndex = 0; // http://blog.geekingfrog.com/reuse-javascript-regexp-global-flag-gotcha/
473477
var result = regexp.exec(command);
474478

475479
if (result) {
@@ -764,6 +768,7 @@ ProcessProxy.prototype._evalRegexConfigs = function(regexConfs, dataToEval) {
764768
var regexConf = regexConfs[i];
765769

766770
if (regexConf.hasOwnProperty('regExpObj')) {
771+
regexConf.regExpObj.lastIndex = 0; // http://blog.geekingfrog.com/reuse-javascript-regexp-global-flag-gotcha/
767772
var matches = regexConf.regExpObj.exec(dataToEval);
768773

769774
if (matches && regexConf.invalidOn == 'match' ||

0 commit comments

Comments
 (0)