diff --git a/lib/repl.js b/lib/repl.js index e4364e7d11cc42..f3e08efa813e93 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 00000000000000..e9794d9bea45c6 --- /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); + }); +}