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:
parent
f0d4237ef5
commit
c7b60165a6
@ -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';
|
||||||
|
29
test/parallel/test-repl-empty.js
Normal file
29
test/parallel/test-repl-empty.js
Normal 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);
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user