From 006cda5dd6edd13f73df9a37bececaf104aa7ca6 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Mon, 3 Jun 2019 00:48:53 +0200 Subject: [PATCH 1/2] 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 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig --- lib/readline.js | 2 +- test/parallel/test-readline-interface.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/readline.js b/lib/readline.js index c8d0a8040ad971..5cc229388219e8 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -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); } diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index 2dff11f2a27e72..93c4b12511eef7 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -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 From f832e8665e07828a5393d4bf8103ad8c7b4a1d67 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Mon, 10 Jun 2019 13:09:12 -0700 Subject: [PATCH 2/2] readline: revert semver-major of 28109 PR-URL: https://github.com/nodejs/node/pull/28109 --- lib/readline.js | 2 +- test/parallel/test-readline-interface.js | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index 5cc229388219e8..c8d0a8040ad971 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -121,7 +121,7 @@ function Interface(input, output, completer, terminal) { input = input.input; } - if (completer !== undefined && typeof completer !== 'function') { + if (completer && typeof completer !== 'function') { throw new ERR_INVALID_OPT_VALUE('completer', completer); } diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index 93c4b12511eef7..b941c8d6eae88c 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -367,25 +367,19 @@ function isWarned(emitter) { code: 'ERR_INVALID_OPT_VALUE' }); - common.expectsError(function() { + common.mustCall(function() { readline.createInterface({ input: fi, completer: '' }); - }, { - type: TypeError, - code: 'ERR_INVALID_OPT_VALUE' - }); + })(); - common.expectsError(function() { + common.mustCall(function() { readline.createInterface({ input: fi, completer: false }); - }, { - type: TypeError, - code: 'ERR_INVALID_OPT_VALUE' - }); + })(); } // Constructor throws if historySize is not a positive number