From 362a7c0d8b3fb76964fd824a02a4dd96162f38d6 Mon Sep 17 00:00:00 2001 From: Shivanth MP Date: Sun, 23 Jul 2017 21:47:07 +0530 Subject: [PATCH] repl: do not consider `...` as a REPL command This fix makes ... in REPL to be considered as a javascript construct rather than a REPL keyword. Fixes: https://github.com/nodejs/node/issues/14426 Backport-PR-URL: https://github.com/nodejs/node/pull/14915 PR-URL: https://github.com/nodejs/node/pull/14467 Reviewed-By: Roman Reiss Reviewed-By: Anna Henningsen Reviewed-By: Jeremiah Senkpiel --- lib/repl.js | 9 +++++---- test/parallel/test-repl.js | 8 +++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index b48242be1bc763..127fd80bf82f65 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -519,10 +519,11 @@ function REPLServer(prompt, // Check to see if a REPL keyword was used. If it returns true, // display next prompt and return. - if (cmd && cmd.charAt(0) === '.' && isNaN(parseFloat(cmd))) { - var matches = cmd.match(/^\.([^\s]+)\s*(.*)$/); - var keyword = matches && matches[1]; - var rest = matches && matches[2]; + if (cmd && cmd.charAt(0) === '.' && cmd.charAt(1) !== '.' && + isNaN(parseFloat(cmd))) { + const matches = cmd.match(/^\.([^\s]+)\s*(.*)$/); + const keyword = matches && matches[1]; + const rest = matches && matches[2]; if (self.parseREPLKeyword(keyword, rest) === true) { return; } else if (!self.bufferedCommand) { diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index c471b185dd6531..3b705f7b6be97f 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -387,7 +387,13 @@ function error_test() { { client: client_unix, send: '(function() {\nif (false) {} /bar"/;\n}())', expect: `${prompt_multiline}${prompt_multiline}undefined\n${prompt_unix}` - } + }, + // Do not parse `...[]` as a REPL keyword + { client: client_unix, send: '...[]\n', + expect: `${prompt_multiline}` }, + // bring back the repl to prompt + { client: client_unix, send: '.break', + expect: `${prompt_unix}` } ]); }