mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
dns: move falsy hostname in lookup to end-of-life
It's been deprecated for ~7 years. It's time. PR-URL: https://github.com/nodejs/node/pull/58619 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
This commit is contained in:
parent
431c04d0bd
commit
a5f9ca1f77
|
|
@ -2524,17 +2524,18 @@ object can lead to crashing the application.
|
|||
|
||||
<!-- YAML
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/58619
|
||||
description: End-of-Life.
|
||||
- version: v11.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/23173
|
||||
description: Runtime deprecation.
|
||||
-->
|
||||
|
||||
Type: Runtime
|
||||
Type: End-of-Life
|
||||
|
||||
Previous versions of Node.js supported `dns.lookup()` with a falsy host name
|
||||
like `dns.lookup(false)` due to backward compatibility.
|
||||
This behavior is undocumented and is thought to be unused in real world apps.
|
||||
It will become an error in future versions of Node.js.
|
||||
like `dns.lookup(false)` due to backward compatibility. This has been removed.
|
||||
|
||||
### DEP0119: `process.binding('uv').errname()` private API
|
||||
|
||||
|
|
|
|||
10
lib/dns.js
10
lib/dns.js
|
|
@ -42,7 +42,6 @@ const {
|
|||
bindDefaultResolver,
|
||||
setDefaultResolver,
|
||||
validateHints,
|
||||
emitInvalidHostnameWarning,
|
||||
getDefaultResultOrder,
|
||||
setDefaultResultOrder,
|
||||
errorCodes: dnsErrorCodes,
|
||||
|
|
@ -199,13 +198,8 @@ function lookup(hostname, options, callback) {
|
|||
}
|
||||
|
||||
if (!hostname) {
|
||||
emitInvalidHostnameWarning(hostname);
|
||||
if (all) {
|
||||
process.nextTick(callback, null, []);
|
||||
} else {
|
||||
process.nextTick(callback, null, null, family === 6 ? 6 : 4);
|
||||
}
|
||||
return {};
|
||||
throw new ERR_INVALID_ARG_VALUE('hostname', hostname,
|
||||
'must be a non-empty string');
|
||||
}
|
||||
|
||||
const matchedFamily = isIP(hostname);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ const {
|
|||
bindDefaultResolver,
|
||||
createResolverClass,
|
||||
validateHints,
|
||||
emitInvalidHostnameWarning,
|
||||
errorCodes: dnsErrorCodes,
|
||||
getDefaultResultOrder,
|
||||
setDefaultResultOrder,
|
||||
|
|
@ -135,8 +134,8 @@ function onlookupall(err, addresses) {
|
|||
function createLookupPromise(family, hostname, all, hints, dnsOrder) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!hostname) {
|
||||
emitInvalidHostnameWarning(hostname);
|
||||
resolve(all ? [] : { address: null, family: family === 6 ? 6 : 4 });
|
||||
reject(new ERR_INVALID_ARG_VALUE('hostname', hostname,
|
||||
'must be a non-empty string'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -269,19 +269,6 @@ function validateHints(hints) {
|
|||
}
|
||||
}
|
||||
|
||||
let invalidHostnameWarningEmitted = false;
|
||||
function emitInvalidHostnameWarning(hostname) {
|
||||
if (!invalidHostnameWarningEmitted) {
|
||||
process.emitWarning(
|
||||
`The provided hostname "${hostname}" is not a valid ` +
|
||||
'hostname, and is supported in the dns module solely for compatibility.',
|
||||
'DeprecationWarning',
|
||||
'DEP0118',
|
||||
);
|
||||
invalidHostnameWarningEmitted = true;
|
||||
}
|
||||
}
|
||||
|
||||
function setDefaultResultOrder(value) {
|
||||
validateOneOf(value, 'dnsOrder', validDnsOrders);
|
||||
dnsOrder = value;
|
||||
|
|
@ -352,7 +339,6 @@ module.exports = {
|
|||
validateHints,
|
||||
validateTimeout,
|
||||
validateTries,
|
||||
emitInvalidHostnameWarning,
|
||||
getDefaultResultOrder,
|
||||
setDefaultResultOrder,
|
||||
errorCodes,
|
||||
|
|
|
|||
|
|
@ -629,21 +629,6 @@ TEST(function test_lookup_ip_promise(done) {
|
|||
});
|
||||
|
||||
|
||||
TEST(async function test_lookup_null_all(done) {
|
||||
assert.deepStrictEqual(await dnsPromises.lookup(null, { all: true }), []);
|
||||
|
||||
const req = dns.lookup(null, { all: true }, (err, ips) => {
|
||||
assert.ifError(err);
|
||||
assert.ok(Array.isArray(ips));
|
||||
assert.strictEqual(ips.length, 0);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
checkWrap(req);
|
||||
});
|
||||
|
||||
|
||||
TEST(async function test_lookup_all_mixed(done) {
|
||||
function validateResult(result) {
|
||||
assert.ok(Array.isArray(result));
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ const dnsPromises = dns.promises;
|
|||
(async function() {
|
||||
let res;
|
||||
|
||||
res = await dnsPromises.lookup(null);
|
||||
assert.strictEqual(res.address, null);
|
||||
assert.strictEqual(res.family, 4);
|
||||
await assert.rejects(dnsPromises.lookup(null), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
|
||||
res = await dnsPromises.lookup('127.0.0.1');
|
||||
assert.strictEqual(res.address, '127.0.0.1');
|
||||
|
|
@ -43,10 +43,9 @@ const dnsPromises = dns.promises;
|
|||
})().then(common.mustCall());
|
||||
|
||||
// Try resolution without hostname.
|
||||
dns.lookup(null, common.mustSucceed((result, addressType) => {
|
||||
assert.strictEqual(result, null);
|
||||
assert.strictEqual(addressType, 4);
|
||||
}));
|
||||
assert.throws(() => dns.lookup(null, common.mustNotCall()), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
|
||||
dns.lookup('127.0.0.1', common.mustSucceed((result, addressType) => {
|
||||
assert.strictEqual(result, '127.0.0.1');
|
||||
|
|
|
|||
|
|
@ -29,11 +29,6 @@ common.expectWarning({
|
|||
'internal/test/binding': [
|
||||
'These APIs are for internal testing only. Do not use them.',
|
||||
],
|
||||
// For calling `dns.lookup` with falsy `hostname`.
|
||||
'DeprecationWarning': {
|
||||
DEP0118: 'The provided hostname "false" is not a valid ' +
|
||||
'hostname, and is supported in the dns module solely for compatibility.'
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(() => {
|
||||
|
|
@ -145,12 +140,13 @@ assert.throws(() => dnsPromises.lookup(false, () => {}),
|
|||
(async function() {
|
||||
let res;
|
||||
|
||||
res = await dnsPromises.lookup(false, {
|
||||
await assert.rejects(dnsPromises.lookup(false, {
|
||||
hints: 0,
|
||||
family: 0,
|
||||
all: true
|
||||
}), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
assert.deepStrictEqual(res, []);
|
||||
|
||||
res = await dnsPromises.lookup('127.0.0.1', {
|
||||
hints: 0,
|
||||
|
|
@ -167,14 +163,13 @@ assert.throws(() => dnsPromises.lookup(false, () => {}),
|
|||
assert.deepStrictEqual(res, { address: '127.0.0.1', family: 4 });
|
||||
})().then(common.mustCall());
|
||||
|
||||
dns.lookup(false, {
|
||||
assert.throws(() => dns.lookup(false, {
|
||||
hints: 0,
|
||||
family: 0,
|
||||
all: true
|
||||
}, common.mustSucceed((result, addressType) => {
|
||||
assert.deepStrictEqual(result, []);
|
||||
assert.strictEqual(addressType, undefined);
|
||||
}));
|
||||
}, common.mustNotCall()), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
|
||||
dns.lookup('127.0.0.1', {
|
||||
hints: 0,
|
||||
|
|
|
|||
|
|
@ -193,16 +193,13 @@ assert.deepStrictEqual(dns.getServers(), []);
|
|||
|
||||
// dns.lookup should accept falsey values
|
||||
{
|
||||
const checkCallback = (err, address, family) => {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(address, null);
|
||||
assert.strictEqual(family, 4);
|
||||
};
|
||||
|
||||
['', null, undefined, 0, NaN].forEach(async (value) => {
|
||||
const res = await dnsPromises.lookup(value);
|
||||
assert.deepStrictEqual(res, { address: null, family: 4 });
|
||||
dns.lookup(value, common.mustCall(checkCallback));
|
||||
await assert.rejects(dnsPromises.lookup(value), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
assert.throws(() => dns.lookup(value, common.mustNotCall()), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -247,52 +244,104 @@ assert.throws(() => dns.lookup('', {
|
|||
name: 'TypeError'
|
||||
});
|
||||
|
||||
dns.lookup('', { family: 4, hints: 0 }, common.mustCall());
|
||||
assert.throws(() => {
|
||||
dns.lookup('', { family: 4, hints: 0 }, common.mustNotCall());
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
|
||||
dns.lookup('', {
|
||||
assert.throws(() => {
|
||||
dns.lookup('', {
|
||||
family: 6,
|
||||
hints: dns.ADDRCONFIG
|
||||
}, common.mustCall());
|
||||
}, common.mustNotCall());
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
|
||||
dns.lookup('', { hints: dns.V4MAPPED }, common.mustCall());
|
||||
assert.throws(() => {
|
||||
dns.lookup('', { hints: dns.V4MAPPED }, common.mustNotCall());
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
|
||||
dns.lookup('', {
|
||||
assert.throws(() => {
|
||||
dns.lookup('', {
|
||||
hints: dns.ADDRCONFIG | dns.V4MAPPED
|
||||
}, common.mustCall());
|
||||
}, common.mustNotCall());
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
|
||||
dns.lookup('', {
|
||||
assert.throws(() => {
|
||||
dns.lookup('', {
|
||||
hints: dns.ALL
|
||||
}, common.mustCall());
|
||||
}, common.mustNotCall());
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
|
||||
dns.lookup('', {
|
||||
assert.throws(() => {
|
||||
dns.lookup('', {
|
||||
hints: dns.V4MAPPED | dns.ALL
|
||||
}, common.mustCall());
|
||||
}, common.mustNotCall());
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
|
||||
dns.lookup('', {
|
||||
assert.throws(() => {
|
||||
dns.lookup('', {
|
||||
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
|
||||
}, common.mustCall());
|
||||
}, common.mustNotCall());
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
|
||||
dns.lookup('', {
|
||||
assert.throws(() => {
|
||||
dns.lookup('', {
|
||||
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL,
|
||||
family: 'IPv4'
|
||||
}, common.mustCall());
|
||||
}, common.mustNotCall());
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
|
||||
dns.lookup('', {
|
||||
assert.throws(() => {
|
||||
dns.lookup('', {
|
||||
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL,
|
||||
family: 'IPv6'
|
||||
}, common.mustCall());
|
||||
}, common.mustNotCall());
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
|
||||
(async function() {
|
||||
await dnsPromises.lookup('', { family: 4, hints: 0 });
|
||||
await dnsPromises.lookup('', { family: 6, hints: dns.ADDRCONFIG });
|
||||
await dnsPromises.lookup('', { hints: dns.V4MAPPED });
|
||||
await dnsPromises.lookup('', { hints: dns.ADDRCONFIG | dns.V4MAPPED });
|
||||
await dnsPromises.lookup('', { hints: dns.ALL });
|
||||
await dnsPromises.lookup('', { hints: dns.V4MAPPED | dns.ALL });
|
||||
await dnsPromises.lookup('', {
|
||||
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
|
||||
await assert.rejects(dnsPromises.lookup('', { family: 4, hints: 0 }), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
await assert.rejects(dnsPromises.lookup('', { family: 6, hints: dns.ADDRCONFIG }), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
await assert.rejects(dnsPromises.lookup('', { hints: dns.V4MAPPED }), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
await assert.rejects(dnsPromises.lookup('', { hints: dns.ADDRCONFIG | dns.V4MAPPED }), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
await assert.rejects(dnsPromises.lookup('', { hints: dns.ALL }), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
await assert.rejects(dnsPromises.lookup('', { hints: dns.V4MAPPED | dns.ALL }), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
await assert.rejects(dnsPromises.lookup('', {
|
||||
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
|
||||
}), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
await assert.rejects(dnsPromises.lookup('', { order: 'verbatim' }), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
await dnsPromises.lookup('', { order: 'verbatim' });
|
||||
})().then(common.mustCall());
|
||||
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user