Skip to content

Commit 1b6f491

Browse files
committed
dns: move falsy hostname in lookup to end-of-life
It's been deprecated for ~7 years. It's time.
1 parent 3c351c2 commit 1b6f491

5 files changed

Lines changed: 16 additions & 41 deletions

File tree

doc/api/deprecations.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,17 +2521,18 @@ object can lead to crashing the application.
25212521

25222522
<!-- YAML
25232523
changes:
2524+
- version: REPLACEME
2525+
pr-url: https://github.com/nodejs/node/pull/00000
2526+
description: End-of-Life.
25242527
- version: v11.0.0
25252528
pr-url: https://github.com/nodejs/node/pull/23173
25262529
description: Runtime deprecation.
25272530
-->
25282531

2529-
Type: Runtime
2532+
Type: End-of-Life
25302533

25312534
Previous versions of Node.js supported `dns.lookup()` with a falsy host name
2532-
like `dns.lookup(false)` due to backward compatibility.
2533-
This behavior is undocumented and is thought to be unused in real world apps.
2534-
It will become an error in future versions of Node.js.
2535+
like `dns.lookup(false)` due to backward compatibility. This has been removed.
25352536

25362537
### DEP0119: `process.binding('uv').errname()` private API
25372538

lib/dns.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const {
4242
bindDefaultResolver,
4343
setDefaultResolver,
4444
validateHints,
45-
emitInvalidHostnameWarning,
4645
getDefaultResultOrder,
4746
setDefaultResultOrder,
4847
errorCodes: dnsErrorCodes,
@@ -199,13 +198,8 @@ function lookup(hostname, options, callback) {
199198
}
200199

201200
if (!hostname) {
202-
emitInvalidHostnameWarning(hostname);
203-
if (all) {
204-
process.nextTick(callback, null, []);
205-
} else {
206-
process.nextTick(callback, null, null, family === 6 ? 6 : 4);
207-
}
208-
return {};
201+
throw new ERR_INVALID_ARG_VALUE('hostname', hostname,
202+
'must be a non-empty string');
209203
}
210204

211205
const matchedFamily = isIP(hostname);

lib/internal/dns/promises.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const {
1111
bindDefaultResolver,
1212
createResolverClass,
1313
validateHints,
14-
emitInvalidHostnameWarning,
1514
errorCodes: dnsErrorCodes,
1615
getDefaultResultOrder,
1716
setDefaultResultOrder,
@@ -135,8 +134,8 @@ function onlookupall(err, addresses) {
135134
function createLookupPromise(family, hostname, all, hints, dnsOrder) {
136135
return new Promise((resolve, reject) => {
137136
if (!hostname) {
138-
emitInvalidHostnameWarning(hostname);
139-
resolve(all ? [] : { address: null, family: family === 6 ? 6 : 4 });
137+
reject(new ERR_INVALID_ARG_VALUE('hostname', hostname,
138+
'must be a non-empty string'));
140139
return;
141140
}
142141

lib/internal/dns/utils.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,6 @@ function validateHints(hints) {
269269
}
270270
}
271271

272-
let invalidHostnameWarningEmitted = false;
273-
function emitInvalidHostnameWarning(hostname) {
274-
if (!invalidHostnameWarningEmitted) {
275-
process.emitWarning(
276-
`The provided hostname "${hostname}" is not a valid ` +
277-
'hostname, and is supported in the dns module solely for compatibility.',
278-
'DeprecationWarning',
279-
'DEP0118',
280-
);
281-
invalidHostnameWarningEmitted = true;
282-
}
283-
}
284-
285272
function setDefaultResultOrder(value) {
286273
validateOneOf(value, 'dnsOrder', validDnsOrders);
287274
dnsOrder = value;
@@ -352,7 +339,6 @@ module.exports = {
352339
validateHints,
353340
validateTimeout,
354341
validateTries,
355-
emitInvalidHostnameWarning,
356342
getDefaultResultOrder,
357343
setDefaultResultOrder,
358344
errorCodes,

test/parallel/test-dns-lookup.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ common.expectWarning({
2929
'internal/test/binding': [
3030
'These APIs are for internal testing only. Do not use them.',
3131
],
32-
// For calling `dns.lookup` with falsy `hostname`.
33-
'DeprecationWarning': {
34-
DEP0118: 'The provided hostname "false" is not a valid ' +
35-
'hostname, and is supported in the dns module solely for compatibility.'
36-
}
3732
});
3833

3934
assert.throws(() => {
@@ -145,12 +140,13 @@ assert.throws(() => dnsPromises.lookup(false, () => {}),
145140
(async function() {
146141
let res;
147142

148-
res = await dnsPromises.lookup(false, {
143+
await assert.rejects(dnsPromises.lookup(false, {
149144
hints: 0,
150145
family: 0,
151146
all: true
147+
}), {
148+
code: 'ERR_INVALID_ARG_VALUE',
152149
});
153-
assert.deepStrictEqual(res, []);
154150

155151
res = await dnsPromises.lookup('127.0.0.1', {
156152
hints: 0,
@@ -167,14 +163,13 @@ assert.throws(() => dnsPromises.lookup(false, () => {}),
167163
assert.deepStrictEqual(res, { address: '127.0.0.1', family: 4 });
168164
})().then(common.mustCall());
169165

170-
dns.lookup(false, {
166+
assert.throws(() => dns.lookup(false, {
171167
hints: 0,
172168
family: 0,
173169
all: true
174-
}, common.mustSucceed((result, addressType) => {
175-
assert.deepStrictEqual(result, []);
176-
assert.strictEqual(addressType, undefined);
177-
}));
170+
}, common.mustNotCall()), {
171+
code: 'ERR_INVALID_ARG_VALUE',
172+
});
178173

179174
dns.lookup('127.0.0.1', {
180175
hints: 0,

0 commit comments

Comments
 (0)