From c7b60165a61520941b0e3c18d79b89a88c60d720 Mon Sep 17 00:00:00 2001 From: Jan Krems Date: Wed, 15 Mar 2017 13:48:11 -0700 Subject: [PATCH] repl: Empty command should be sent to eval function This fixes a regression introduced in https://github.com/nodejs/node/pull/6171 PR-URL: https://github.com/nodejs/node/pull/11871 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- lib/repl.js | 6 ------ test/parallel/test-repl-empty.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 test/parallel/test-repl-empty.js diff --git a/lib/repl.js b/lib/repl.js index e4364e7d11c..f3e08efa813 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -422,12 +422,6 @@ function REPLServer(prompt, return; } } - } else { - // Print a new line when hitting enter. - if (!self.bufferedCommand) { - finish(null); - return; - } } const evalCmd = self.bufferedCommand + cmd + '\n'; diff --git a/test/parallel/test-repl-empty.js b/test/parallel/test-repl-empty.js new file mode 100644 index 00000000000..e9794d9bea4 --- /dev/null +++ b/test/parallel/test-repl-empty.js @@ -0,0 +1,29 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const repl = require('repl'); + +{ + let evalCalledWithExpectedArgs = false; + + const options = { + eval: common.mustCall((cmd, context) => { + // Assertions here will not cause the test to exit with an error code + // so set a boolean that is checked in process.on('exit',...) instead. + evalCalledWithExpectedArgs = (cmd === '\n'); + }) + }; + + const r = repl.start(options); + + try { + // Empty strings should be sent to the repl's eval function + r.write('\n'); + } finally { + r.write('.exit\n'); + } + + process.on('exit', () => { + assert(evalCalledWithExpectedArgs); + }); +}