From 13fc22f848435918fdcd30524a5151df9a1171ba Mon Sep 17 00:00:00 2001 From: Prince J Wesley Date: Sat, 6 Feb 2016 12:14:27 +0530 Subject: [PATCH] repl: handle quotes within regexp literal in multiline mode --- lib/repl.js | 16 +++++++++++++--- test/parallel/test-repl.js | 13 +++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index 5ba1bfc115eb6d..5077925968bae7 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -84,6 +84,7 @@ class LineParser { this._literal = null; this.shouldFail = false; this.blockComment = false; + this.regExpLiteral = false; } parseLine(line) { @@ -99,6 +100,11 @@ class LineParser { } if (!this._literal) { + if (this.regExpLiteral && current === '/') { + this.regExpLiteral = false; + previous = null; + continue; + } if (previous === '*' && current === '/') { if (this.blockComment) { this.blockComment = false; @@ -115,13 +121,17 @@ class LineParser { break; } - if (previous === '/' && current === '*') { - this.blockComment = true; + if (previous === '/') { + if (current === '*') { + this.blockComment = true; + } else { + this.regExpLiteral = true; + } previous = null; } } - if (this.blockComment) continue; + if (this.blockComment || this.regExpLiteral) continue; if (current === this._literal) { this._literal = null; diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index d9e69cd6140b1f..aa5d8d26809570 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -287,6 +287,19 @@ function error_test() { // access to internal modules without the --expose_internals flag. { client: client_unix, send: 'require("internal/repl")', expect: /^Error: Cannot find module 'internal\/repl'/ }, + // REPL should handle quotes within regexp literal in multiline mode + { client: client_unix, send: "function x(s) {\nreturn s.replace(/'/,'');\n}", + expect: prompt_multiline + prompt_multiline + + 'undefined\n' + prompt_unix }, + { client: client_unix, send: "function x(s) {\nreturn s.replace(/\'/,'');\n}", + expect: prompt_multiline + prompt_multiline + + 'undefined\n' + prompt_unix }, + { client: client_unix, send: 'function x(s) {\nreturn s.replace(/"/,"");\n}', + expect: prompt_multiline + prompt_multiline + + 'undefined\n' + prompt_unix }, + { client: client_unix, send: 'function x(s) {\nreturn s.replace(/.*/,"");\n}', + expect: prompt_multiline + prompt_multiline + + 'undefined\n' + prompt_unix }, ]); }