diff options
author | Ouyang Yadong <oyydoibh@gmail.com> | 2018-09-30 18:17:36 +0800 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-10-04 14:51:02 -0700 |
commit | 26af72899417525dd32372d63c07ee5aa1ab6c5c (patch) | |
tree | 0effe53f03127f80998733507adb88fdf8399f4b /lib/internal/dns | |
parent | 6f7fd7f9bc743f7244f820a1b7be1e01562c96fd (diff) | |
download | android-node-v8-26af72899417525dd32372d63c07ee5aa1ab6c5c.tar.gz android-node-v8-26af72899417525dd32372d63c07ee5aa1ab6c5c.tar.bz2 android-node-v8-26af72899417525dd32372d63c07ee5aa1ab6c5c.zip |
dns: deprecate passing falsy hostname to dns.lookup
We can `dns.lookup` a falsy `hostname` like `dns.lookup(false)`
for the reason of backwards compatibility long before(see #13119
for detail). This behavior is undocumented and seems useless in
real world apps.
We could also make invalid `hostname` throw in the future and the
change might be semver-major.
Fixes: https://github.com/nodejs/node/issues/13119
PR-URL: https://github.com/nodejs/node/pull/23173
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/internal/dns')
-rw-r--r-- | lib/internal/dns/promises.js | 6 | ||||
-rw-r--r-- | lib/internal/dns/utils.js | 18 |
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js index 6d2fa3b170..8baa0fa0de 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -2,7 +2,8 @@ const { bindDefaultResolver, Resolver: CallbackResolver, - validateHints + validateHints, + emitInvalidHostnameWarning, } = require('internal/dns/utils'); const { codes, dnsException } = require('internal/errors'); const { isIP, isIPv4, isLegalPort } = require('internal/net'); @@ -55,6 +56,7 @@ function onlookupall(err, addresses) { function createLookupPromise(family, hostname, all, hints, verbatim) { return new Promise((resolve, reject) => { if (!hostname) { + emitInvalidHostnameWarning(hostname); if (all) resolve([]); else @@ -99,7 +101,7 @@ function lookup(hostname, options) { // Parse arguments if (hostname && typeof hostname !== 'string') { - throw new ERR_INVALID_ARG_TYPE('hostname', ['string', 'falsy'], hostname); + throw new ERR_INVALID_ARG_TYPE('hostname', 'string', hostname); } else if (options !== null && typeof options === 'object') { hints = options.hints >>> 0; family = options.family >>> 0; diff --git a/lib/internal/dns/utils.js b/lib/internal/dns/utils.js index 143d36193a..d279a58840 100644 --- a/lib/internal/dns/utils.js +++ b/lib/internal/dns/utils.js @@ -140,10 +140,26 @@ function validateHints(hints) { } } +let invalidHostnameWarningEmitted = false; + +function emitInvalidHostnameWarning(hostname) { + if (invalidHostnameWarningEmitted) { + return; + } + invalidHostnameWarningEmitted = true; + process.emitWarning( + `The provided hostname "${hostname}" is not a valid ` + + 'hostname, and is supported in the dns module solely for compatibility.', + 'DeprecationWarning', + 'DEP0118' + ); +} + module.exports = { bindDefaultResolver, getDefaultResolver, setDefaultResolver, validateHints, - Resolver + Resolver, + emitInvalidHostnameWarning, }; |