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 <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Jan Krems 2017-03-15 13:48:11 -07:00 committed by James M Snell
parent f0d4237ef5
commit c7b60165a6
2 changed files with 29 additions and 6 deletions

View File

@ -422,12 +422,6 @@ function REPLServer(prompt,
return; return;
} }
} }
} else {
// Print a new line when hitting enter.
if (!self.bufferedCommand) {
finish(null);
return;
}
} }
const evalCmd = self.bufferedCommand + cmd + '\n'; const evalCmd = self.bufferedCommand + cmd + '\n';

View File

@ -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);
});
}