readline: error on falsy values for callback

It was intended, according to in-test comments and common behaviour,
that callbacks be either `undefined` or a function, but falsy values
were being accepted as meaning "no callback".

PR-URL: https://github.com/nodejs/node/pull/28109
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Sam Roberts 2019-06-03 00:48:53 +02:00
parent b17a70f639
commit 04633eeeb9
2 changed files with 21 additions and 1 deletions

View File

@ -121,7 +121,7 @@ function Interface(input, output, completer, terminal) {
input = input.input;
}
if (completer && typeof completer !== 'function') {
if (completer !== undefined && typeof completer !== 'function') {
throw new ERR_INVALID_OPT_VALUE('completer', completer);
}

View File

@ -366,6 +366,26 @@ function isWarned(emitter) {
type: TypeError,
code: 'ERR_INVALID_OPT_VALUE'
});
common.expectsError(function() {
readline.createInterface({
input: fi,
completer: ''
});
}, {
type: TypeError,
code: 'ERR_INVALID_OPT_VALUE'
});
common.expectsError(function() {
readline.createInterface({
input: fi,
completer: false
});
}, {
type: TypeError,
code: 'ERR_INVALID_OPT_VALUE'
});
}
// Constructor throws if historySize is not a positive number