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 nodejs#6171

PR-URL: nodejs#11871
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
Jan Krems authored and jungx098 committed Mar 21, 2017
1 parent 249ecef commit fb43588
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 fb43588

Please sign in to comment.