Skip to content

Commit

Permalink
repl: Empty command should be sent to eval function
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Jan Krems authored and jasnell committed Mar 17, 2017
1 parent f0d4237 commit c7b6016
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
6 changes: 0 additions & 6 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
29 changes: 29 additions & 0 deletions test/parallel/test-repl-empty.js
Original file line number Diff line number Diff line change
@@ -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);
});
}

0 comments on commit c7b6016

Please sign in to comment.