Skip to content

Commit c7b6016

Browse files
Jan Kremsjasnell
Jan Krems
authored andcommitted
repl: Empty command should be sent to eval function
This fixes a regression introduced in #6171 PR-URL: #11871 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent f0d4237 commit c7b6016

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/repl.js

-6
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,6 @@ function REPLServer(prompt,
422422
return;
423423
}
424424
}
425-
} else {
426-
// Print a new line when hitting enter.
427-
if (!self.bufferedCommand) {
428-
finish(null);
429-
return;
430-
}
431425
}
432426

433427
const evalCmd = self.bufferedCommand + cmd + '\n';

test/parallel/test-repl-empty.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const repl = require('repl');
5+
6+
{
7+
let evalCalledWithExpectedArgs = false;
8+
9+
const options = {
10+
eval: common.mustCall((cmd, context) => {
11+
// Assertions here will not cause the test to exit with an error code
12+
// so set a boolean that is checked in process.on('exit',...) instead.
13+
evalCalledWithExpectedArgs = (cmd === '\n');
14+
})
15+
};
16+
17+
const r = repl.start(options);
18+
19+
try {
20+
// Empty strings should be sent to the repl's eval function
21+
r.write('\n');
22+
} finally {
23+
r.write('.exit\n');
24+
}
25+
26+
process.on('exit', () => {
27+
assert(evalCalledWithExpectedArgs);
28+
});
29+
}

0 commit comments

Comments
 (0)