Skip to content

Commit

Permalink
readline: error on falsy values for callback
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
sam-github committed Jun 7, 2019
1 parent 6447be6 commit 7420235
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7420235

Please sign in to comment.