Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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".
  • Loading branch information
sam-github committed Jun 7, 2019
commit 7420235e5a1702acf2063db687afce99b1c0eab3
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