-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: repl clobbers RegExp.$1 #597
Comments
is this the same issue: nodejs/node-v0.x-archive#4088 ? |
Yes, it is. I'd forgotten about that other issue, actually. |
As an idea: we can execute regexps in a different context |
Given that we have a patch, this would make a good first bug for anyone with the time to PR it in. |
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. |
Reproducing here for posterity: 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 Aside: using |
@bnoordhuis Thanks for helping me understand :-) |
Fixes: nodejs#597 In REPL, if we evaluate the `RegExp` object's predefined properties, and if they happen to have the same expression, for example, > RegExp.$1 'RegExp.$1' then doing `eval(RegExp.$1)` would evluated `RegExp.$1` recursively and eventually throw `RangeError: Maximum call stack size exceeded`. This patch stores the old values of `RegExp`'s predefined proprties and restores them just before the current expression entered by user is evaluated.
In REPL, if we evaluate the `RegExp` object's predefined properties, and if they happen to have the same expression, for example, > RegExp.$1 'RegExp.$1' then doing `eval(RegExp.$1)` would evaluate `RegExp.$1` recursively and eventually throw `RangeError: Maximum call stack size exceeded`. This patch stores the old values of `RegExp`'s predefined proprties in an array and restores them just before the current expression entered by user is evaluated. Fixes: #597 PR-URL: #2137 Reviewed-By: Ben Noordhuis <[email protected]>
In light of #2137's landing, closing this bug. |
In REPL, if we evaluate the `RegExp` object's predefined properties, and if they happen to have the same expression, for example, > RegExp.$1 'RegExp.$1' then doing `eval(RegExp.$1)` would evaluate `RegExp.$1` recursively and eventually throw `RangeError: Maximum call stack size exceeded`. This patch stores the old values of `RegExp`'s predefined proprties in an array and restores them just before the current expression entered by user is evaluated. Fixes: nodejs#597 PR-URL: nodejs#2137 Reviewed-By: Ben Noordhuis <[email protected]>
The text was updated successfully, but these errors were encountered: