From 77fa385e5d9fedd32e57646ad6d68735336b20ff Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Sun, 12 Jul 2015 00:53:39 +0000 Subject: [PATCH] repl: fixing `undefined` in invalid REPL keyword error When an invalid REPL keyword is used, we actually print `undefined` as well in the console. > process.version 'v2.3.4' > .invalid_repl_command Invalid REPL keyword undefined > This patch prevents printing `undefined` in this case. > process.version 'v2.3.5-pre' > .invalid_repl_command Invalid REPL keyword > PR-URL: https://github.com/nodejs/io.js/pull/2163 Reviewed-By: Jeremiah Senkpiel --- lib/repl.js | 7 ++++++- test/parallel/test-repl.js | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index 763e283816bb64..11ee6f58216ff6 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -342,7 +342,12 @@ function REPLServer(prompt, self.bufferedCommand = ''; // If we got any output - print it (if no error) - if (!e && (!self.ignoreUndefined || ret !== undefined)) { + if (!e && + // When an invalid REPL command is used, error message is printed + // immediately. We don't have to print anything else. So, only when + // the second argument to this function is there, print it. + arguments.length === 2 && + (!self.ignoreUndefined || ret !== undefined)) { self.context._ = ret; self.outputStream.write(self.writer(ret) + '\n'); } diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 6911c591505fef..94d6bca283cb59 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -189,7 +189,11 @@ function error_test() { { client: client_unix, send: 'url.format("http://google.com")', expect: 'http://google.com/' }, { client: client_unix, send: 'var path = 42; path', - expect: '42' } + expect: '42' }, + // this makes sure that we don't print `undefined` when we actually print + // the error message + { client: client_unix, send: '.invalid_repl_command', + expect: 'Invalid REPL keyword\n' + prompt_unix }, ]); }