You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was looking at it the other day, I was able to reproduce the problem but couldn't understand the fix suggested. I ll spend sometime this week to understand it.
diff --git a/lib/repl.js b/lib/repl.js
index 361745f..fe3077c 100644
--- a/lib/repl.js+++ b/lib/repl.js@@ -104,9 +104,14 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
self.useGlobal = !!useGlobal;
self.ignoreUndefined = !!ignoreUndefined;
+ self._saved = [];
self.eval = eval_ || function(code, context, file, cb) {
var err, result;
++ // restore RegExp.$1 to RegExp.$9+ /^\u0000(.*)\u0000(.*)\u0000(.*)\u0000(.*)\u0000(.*)\u0000(.*)\u0000(.*)\u0000(.*)\u0000(.*)$/.test(self._saved.join('\u0000'));+
try {
if (self.useGlobal) {
result = vm.runInThisContext(code, file);
@@ -116,6 +121,11 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
} catch (e) {
err = e;
}
++ for (var i = 1; i <= 9; ++i) {+ self._saved[i] = RegExp['$' + i];+ }+
cb(err, result);
};
@thefourtheye It works by creating a string from the 9 saved values, then doing a capturing match against that, thereby restoring the values of RegExp.$1 to RegExp.$9.
Aside: using '\u0000' as the separator is probably not unique enough in practice.
Activity
vkurchatkin commentedon Jan 24, 2015
is this the same issue: nodejs/node-v0.x-archive#4088 ?
bnoordhuis commentedon Jan 24, 2015
Yes, it is. I'd forgotten about that other issue, actually.
vkurchatkin commentedon Feb 21, 2015
As an idea: we can execute regexps in a different context
chrisdickinson commentedon Jul 8, 2015
Given that we have a patch, this would make a good first bug for anyone with the time to PR it in.
thefourtheye commentedon Jul 8, 2015
I was looking at it the other day, I was able to reproduce the problem but couldn't understand the fix suggested. I ll spend sometime this week to understand it.
bnoordhuis commentedon Jul 8, 2015
Reproducing here for posterity:
@thefourtheye It works by creating a string from the 9 saved values, then doing a capturing match against that, thereby restoring the values of
RegExp.$1toRegExp.$9.Aside: using
'\u0000'as the separator is probably not unique enough in practice.thefourtheye commentedon Jul 8, 2015
@bnoordhuis Thanks for helping me understand :-)
thefourtheye commentedon Aug 4, 2015
In light of #2137's landing, closing this bug.
repl: don't clobber RegExp.$ properties