Skip to content

Commit 04633ee

Browse files
committed
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: #28109 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent b17a70f commit 04633ee

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/readline.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function Interface(input, output, completer, terminal) {
121121
input = input.input;
122122
}
123123

124-
if (completer && typeof completer !== 'function') {
124+
if (completer !== undefined && typeof completer !== 'function') {
125125
throw new ERR_INVALID_OPT_VALUE('completer', completer);
126126
}
127127

test/parallel/test-readline-interface.js

+20
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,26 @@ function isWarned(emitter) {
366366
type: TypeError,
367367
code: 'ERR_INVALID_OPT_VALUE'
368368
});
369+
370+
common.expectsError(function() {
371+
readline.createInterface({
372+
input: fi,
373+
completer: ''
374+
});
375+
}, {
376+
type: TypeError,
377+
code: 'ERR_INVALID_OPT_VALUE'
378+
});
379+
380+
common.expectsError(function() {
381+
readline.createInterface({
382+
input: fi,
383+
completer: false
384+
});
385+
}, {
386+
type: TypeError,
387+
code: 'ERR_INVALID_OPT_VALUE'
388+
});
369389
}
370390

371391
// Constructor throws if historySize is not a positive number

0 commit comments

Comments
 (0)