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".

PR-URL: #28109
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
sam-github committed Jun 10, 2019
1 parent b17a70f commit 04633ee
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 04633ee

Please sign in to comment.