Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2521,17 +2521,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

Expand Down
10 changes: 2 additions & 8 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const {
bindDefaultResolver,
setDefaultResolver,
validateHints,
emitInvalidHostnameWarning,
getDefaultResultOrder,
setDefaultResultOrder,
errorCodes: dnsErrorCodes,
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions lib/internal/dns/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const {
bindDefaultResolver,
createResolverClass,
validateHints,
emitInvalidHostnameWarning,
errorCodes: dnsErrorCodes,
getDefaultResultOrder,
setDefaultResultOrder,
Expand Down Expand Up @@ -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;
}

Expand Down
14 changes: 0 additions & 14 deletions lib/internal/dns/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -352,7 +339,6 @@ module.exports = {
validateHints,
validateTimeout,
validateTries,
emitInvalidHostnameWarning,
getDefaultResultOrder,
setDefaultResultOrder,
errorCodes,
Expand Down
15 changes: 0 additions & 15 deletions test/internet/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
13 changes: 6 additions & 7 deletions test/parallel/test-c-ares.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down
19 changes: 7 additions & 12 deletions test/parallel/test-dns-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
135 changes: 92 additions & 43 deletions test/parallel/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
});
}

Expand Down Expand Up @@ -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('', {
family: 6,
hints: dns.ADDRCONFIG
}, common.mustCall());
assert.throws(() => {
dns.lookup('', {
family: 6,
hints: dns.ADDRCONFIG
}, 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('', {
hints: dns.ADDRCONFIG | dns.V4MAPPED
}, common.mustCall());
assert.throws(() => {
dns.lookup('', {
hints: dns.ADDRCONFIG | dns.V4MAPPED
}, common.mustNotCall());
}, {
code: 'ERR_INVALID_ARG_VALUE',
});

dns.lookup('', {
hints: dns.ALL
}, common.mustCall());
assert.throws(() => {
dns.lookup('', {
hints: dns.ALL
}, common.mustNotCall());
}, {
code: 'ERR_INVALID_ARG_VALUE',
});

dns.lookup('', {
hints: dns.V4MAPPED | dns.ALL
}, common.mustCall());
assert.throws(() => {
dns.lookup('', {
hints: dns.V4MAPPED | dns.ALL
}, common.mustNotCall());
}, {
code: 'ERR_INVALID_ARG_VALUE',
});

dns.lookup('', {
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
}, common.mustCall());
assert.throws(() => {
dns.lookup('', {
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
}, common.mustNotCall());
}, {
code: 'ERR_INVALID_ARG_VALUE',
});

dns.lookup('', {
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL,
family: 'IPv4'
}, common.mustCall());
assert.throws(() => {
dns.lookup('', {
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL,
family: 'IPv4'
}, common.mustNotCall());
}, {
code: 'ERR_INVALID_ARG_VALUE',
});

dns.lookup('', {
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL,
family: 'IPv6'
}, common.mustCall());
assert.throws(() => {
dns.lookup('', {
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL,
family: 'IPv6'
}, 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('', {
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());

{
Expand Down
Loading