From cb971cc97d217119ab8b3526cf9471caa3ba6ba7 Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Sun, 20 Sep 2015 16:07:21 +0530 Subject: [PATCH] repl: backslash bug fix The actual problem was with the line parsing logic for string literals. When we use backslash in the string literals, it used to remember the `\` as the previous character even after we parsed the character next to it. This leads to REPL thinking that the end of string literals is not reached. This patch replaces the previous character with `null`, so that it will properly skip the character next to it. Previous Discussion: https://github.com/nodejs/node/pull/2952 Fixes: https://github.com/nodejs/node/issues/2749 PR-URL: https://github.com/nodejs/node/pull/2968 Reviewed-By: Roman Reiss --- lib/repl.js | 5 +++-- test/parallel/test-repl.js | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index e61a5ed..81afd27 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -288,8 +288,9 @@ function REPLServer(prompt, for (var i = 0; i < line.length; i += 1) { if (previous === '\\') { - // if it is a valid escaping, then skip processing - previous = current; + // if it is a valid escaping, then skip processing and the previous + // character doesn't matter anymore. + previous = null; continue; } diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index ac890cf..e121cb7 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -242,6 +242,13 @@ function error_test() { 'RegExp.$6\nRegExp.$7\nRegExp.$8\nRegExp.$9\n', expect: ['\'1\'\n', '\'2\'\n', '\'3\'\n', '\'4\'\n', '\'5\'\n', '\'6\'\n', '\'7\'\n', '\'8\'\n', '\'9\'\n'].join(`${prompt_unix}`) }, + // regression tests for https://github.com/nodejs/node/issues/2749 + { client: client_unix, send: 'function x() {\nreturn \'\\n\';\n }', + expect: prompt_multiline + prompt_multiline + + 'undefined\n' + prompt_unix }, + { client: client_unix, send: 'function x() {\nreturn \'\\\\\';\n }', + expect: prompt_multiline + prompt_multiline + + 'undefined\n' + prompt_unix }, ]); } -- 2.7.4