From d5b6ec83ccbb6429946f4646816de7ca5bc1c16b Mon Sep 17 00:00:00 2001 From: Shivanth MP Date: Sun, 23 Jul 2017 21:47:07 +0530 Subject: [PATCH 1/5] 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 --- lib/repl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/repl.js b/lib/repl.js index 79abb35ce289de..5f84454a3faadc 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -419,7 +419,7 @@ function REPLServer(prompt, // Check to see if a REPL keyword was used. If it returns true, // display next prompt and return. if (trimmedCmd) { - if (trimmedCmd.charAt(0) === '.' && isNaN(parseFloat(trimmedCmd))) { + if (trimmedCmd.charAt(0) === '.' && trimmedCmd.charAt(1) != '.' && isNaN(parseFloat(trimmedCmd))) { const matches = trimmedCmd.match(/^\.([^\s]+)\s*(.*)$/); const keyword = matches && matches[1]; const rest = matches && matches[2]; From e2a61f6f44d506e83a764b8b5ec10e2fa645d575 Mon Sep 17 00:00:00 2001 From: Shivanth MP Date: Wed, 26 Jul 2017 00:17:19 +0530 Subject: [PATCH 2/5] use !== instead of != --- lib/repl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/repl.js b/lib/repl.js index 5f84454a3faadc..d2e018d541662a 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -419,7 +419,7 @@ function REPLServer(prompt, // Check to see if a REPL keyword was used. If it returns true, // display next prompt and return. if (trimmedCmd) { - if (trimmedCmd.charAt(0) === '.' && trimmedCmd.charAt(1) != '.' && isNaN(parseFloat(trimmedCmd))) { + if (trimmedCmd.charAt(0) === '.' && trimmedCmd.charAt(1) !== '.' && isNaN(parseFloat(trimmedCmd))) { const matches = trimmedCmd.match(/^\.([^\s]+)\s*(.*)$/); const keyword = matches && matches[1]; const rest = matches && matches[2]; From 067ed9956e72c0c8689dbd3450df13cd79169958 Mon Sep 17 00:00:00 2001 From: Shivanth MP Date: Wed, 26 Jul 2017 19:49:05 +0530 Subject: [PATCH 3/5] Add test for REPL --- test/parallel/test-repl.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 59e5b9cc016f95..12da20eeec2f0c 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -414,7 +414,10 @@ function error_test() { expect: `${prompt_multiline}'foo \\n'\n${prompt_unix}` }, // Whitespace is not evaluated. { client: client_unix, send: ' \t \n', - expect: prompt_unix } + expect: prompt_unix }, + //Do not parse `...[]` as a REPL keyword + { client: client_unix, send: '...[]', + expect: prompt_multiline } ]); } From cfce5a2f86671c1e31f89baad02567c6a39f3b5b Mon Sep 17 00:00:00 2001 From: Shivanth MP Date: Wed, 26 Jul 2017 23:38:59 +0530 Subject: [PATCH 4/5] Fix the test, add the .break command after the test --- test/parallel/test-repl.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 12da20eeec2f0c..ad6a8fb04013f2 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -416,8 +416,8 @@ function error_test() { { client: client_unix, send: ' \t \n', expect: prompt_unix }, //Do not parse `...[]` as a REPL keyword - { client: client_unix, send: '...[]', - expect: prompt_multiline } + { client: client_unix, send: '...[]\n.break', + expect: `${prompt_multiline}${prompt_unix}` } ]); } From 08327ff1b175b0d9459ac99e92fddfc9598f3457 Mon Sep 17 00:00:00 2001 From: Shivanth MP Date: Thu, 27 Jul 2017 23:06:13 +0530 Subject: [PATCH 5/5] Make a more concrete test case --- test/parallel/test-repl.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index ad6a8fb04013f2..a796339fcaaf9d 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -416,8 +416,12 @@ function error_test() { { client: client_unix, send: ' \t \n', expect: prompt_unix }, //Do not parse `...[]` as a REPL keyword - { client: client_unix, send: '...[]\n.break', - expect: `${prompt_multiline}${prompt_unix}` } + { client: client_unix, send: '...[]\n', + expect: `${prompt_multiline}` }, + //bring back the repl to prompt + { client: client_unix, send: '.break', + expect: `${prompt_unix}` } + ]); }