From 0869ef3c55b5c94a1586802869096e9e65aada68 Mon Sep 17 00:00:00 2001 From: Zirak Date: Sun, 15 Nov 2015 14:46:17 +0000 Subject: [PATCH] repl: allow leading period in multiline input When writing multiline input, one can't chain function calls as if the lines begin with a period, since those are treated as REPL commands. Before: > ([0, 1, 2] ... .map(x => x + 1)) Invalid REPL keyword After: > ([0, 1, 2] ... .map(x => x + 1)) [ 1, 2, 3 ] PR-URL: https://github.com/nodejs/node/pull/3835 Reviewed-By: Sakthipriyan Vairamani Reviewed-By: James M Snell Reviewed-By: Trevor Norris Reviewed-By: Jeremiah Senkpiel --- lib/repl.js | 2 +- test/parallel/test-repl.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/repl.js b/lib/repl.js index d0849c3259..be9d6fa72c 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -391,7 +391,7 @@ function REPLServer(prompt, var rest = matches && matches[2]; if (self.parseREPLKeyword(keyword, rest) === true) { return; - } else { + } else if (!self.bufferedCommand) { self.outputStream.write('Invalid REPL keyword\n'); skipCatchall = true; } diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 03792789e8..cda4e9886f 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -117,6 +117,11 @@ function error_test() { expect: prompt_multiline }, { client: client_unix, send: '+ ".2"}`', expect: `'io.js 1.0.2'\n${prompt_unix}` }, + // Dot prefix in multiline commands aren't treated as commands + { client: client_unix, send: '("a"', + expect: prompt_multiline }, + { client: client_unix, send: '.charAt(0))', + expect: `'a'\n${prompt_unix}` }, // Floating point numbers are not interpreted as REPL commands. { client: client_unix, send: '.1234', expect: '0.1234' },