From afd7e37ee04d49b9345df748f5f59fc34c6216e5 Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Sun, 12 Jul 2015 21:48:50 +0000 Subject: [PATCH] repl: better empty line handling In REPL, if we try to evaluate an empty line, we get `undefined`. > process.version 'v2.3.4' > undefined > undefined > This patch prevents `undefined` from printing if the string is empty. > process.version 'v2.3.5-pre' > > > PR-URL: https://github.com/nodejs/io.js/pull/2163 Reviewed-By: Jeremiah Senkpiel --- lib/repl.js | 2 +- test/parallel/test-repl.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/repl.js b/lib/repl.js index d978f27dbf0d6b..1d78a001953bf6 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -357,7 +357,7 @@ function REPLServer(prompt, } } - if (!skipCatchall) { + if (!skipCatchall && (cmd || (!cmd && self.bufferedCommand))) { var evalCmd = self.bufferedCommand + cmd; if (/^\s*\{/.test(evalCmd) && /\}\s*$/.test(evalCmd)) { // It's confusing for `{ a : 1 }` to be interpreted as a block diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 27802c782e0f4e..5829b4a52854c7 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -225,6 +225,13 @@ function error_test() { // using REPL command "help" within a string literal should still work { client: client_unix, send: '\'thefourth\\\n.help\neye\'', expect: /'thefourtheye'/ }, + // empty lines in the REPL should be allowed + { client: client_unix, send: '\n\r\n\r\n', + expect: prompt_unix + prompt_unix + prompt_unix }, + // empty lines in the string literals should not affect the string + { client: client_unix, send: '\'the\\\n\\\nfourtheye\'\n', + expect: prompt_multiline + prompt_multiline + + '\'thefourtheye\'\n' + prompt_unix }, ]); }