Skip to content

Commit a5f9ca1

Browse files
authored
dns: move falsy hostname in lookup to end-of-life
It's been deprecated for ~7 years. It's time. PR-URL: #58619 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 431c04d commit a5f9ca1

File tree

8 files changed

+114
-106
lines changed

8 files changed

+114
-106
lines changed

doc/api/deprecations.md

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

25252525
<!-- YAML
25262526
changes:
2527+
- version: REPLACEME
2528+
pr-url: https://github.com/nodejs/node/pull/58619
2529+
description: End-of-Life.
25272530
- version: v11.0.0
25282531
pr-url: https://github.com/nodejs/node/pull/23173
25292532
description: Runtime deprecation.
25302533
-->
25312534

2532-
Type: Runtime
2535+
Type: End-of-Life
25332536

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

25392540
### DEP0119: `process.binding('uv').errname()` private API
25402541

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/internet/test-dns.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -629,21 +629,6 @@ TEST(function test_lookup_ip_promise(done) {
629629
});
630630

631631

632-
TEST(async function test_lookup_null_all(done) {
633-
assert.deepStrictEqual(await dnsPromises.lookup(null, { all: true }), []);
634-
635-
const req = dns.lookup(null, { all: true }, (err, ips) => {
636-
assert.ifError(err);
637-
assert.ok(Array.isArray(ips));
638-
assert.strictEqual(ips.length, 0);
639-
640-
done();
641-
});
642-
643-
checkWrap(req);
644-
});
645-
646-
647632
TEST(async function test_lookup_all_mixed(done) {
648633
function validateResult(result) {
649634
assert.ok(Array.isArray(result));

test/parallel/test-c-ares.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ const dnsPromises = dns.promises;
2929
(async function() {
3030
let res;
3131

32-
res = await dnsPromises.lookup(null);
33-
assert.strictEqual(res.address, null);
34-
assert.strictEqual(res.family, 4);
32+
await assert.rejects(dnsPromises.lookup(null), {
33+
code: 'ERR_INVALID_ARG_VALUE',
34+
});
3535

3636
res = await dnsPromises.lookup('127.0.0.1');
3737
assert.strictEqual(res.address, '127.0.0.1');
@@ -43,10 +43,9 @@ const dnsPromises = dns.promises;
4343
})().then(common.mustCall());
4444

4545
// Try resolution without hostname.
46-
dns.lookup(null, common.mustSucceed((result, addressType) => {
47-
assert.strictEqual(result, null);
48-
assert.strictEqual(addressType, 4);
49-
}));
46+
assert.throws(() => dns.lookup(null, common.mustNotCall()), {
47+
code: 'ERR_INVALID_ARG_VALUE',
48+
});
5049

5150
dns.lookup('127.0.0.1', common.mustSucceed((result, addressType) => {
5251
assert.strictEqual(result, '127.0.0.1');

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,

test/parallel/test-dns.js

Lines changed: 92 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,13 @@ assert.deepStrictEqual(dns.getServers(), []);
193193

194194
// dns.lookup should accept falsey values
195195
{
196-
const checkCallback = (err, address, family) => {
197-
assert.ifError(err);
198-
assert.strictEqual(address, null);
199-
assert.strictEqual(family, 4);
200-
};
201-
202196
['', null, undefined, 0, NaN].forEach(async (value) => {
203-
const res = await dnsPromises.lookup(value);
204-
assert.deepStrictEqual(res, { address: null, family: 4 });
205-
dns.lookup(value, common.mustCall(checkCallback));
197+
await assert.rejects(dnsPromises.lookup(value), {
198+
code: 'ERR_INVALID_ARG_VALUE',
199+
});
200+
assert.throws(() => dns.lookup(value, common.mustNotCall()), {
201+
code: 'ERR_INVALID_ARG_VALUE',
202+
});
206203
});
207204
}
208205

@@ -247,52 +244,104 @@ assert.throws(() => dns.lookup('', {
247244
name: 'TypeError'
248245
});
249246

250-
dns.lookup('', { family: 4, hints: 0 }, common.mustCall());
247+
assert.throws(() => {
248+
dns.lookup('', { family: 4, hints: 0 }, common.mustNotCall());
249+
}, {
250+
code: 'ERR_INVALID_ARG_VALUE',
251+
});
251252

252-
dns.lookup('', {
253-
family: 6,
254-
hints: dns.ADDRCONFIG
255-
}, common.mustCall());
253+
assert.throws(() => {
254+
dns.lookup('', {
255+
family: 6,
256+
hints: dns.ADDRCONFIG
257+
}, common.mustNotCall());
258+
}, {
259+
code: 'ERR_INVALID_ARG_VALUE',
260+
});
256261

257-
dns.lookup('', { hints: dns.V4MAPPED }, common.mustCall());
262+
assert.throws(() => {
263+
dns.lookup('', { hints: dns.V4MAPPED }, common.mustNotCall());
264+
}, {
265+
code: 'ERR_INVALID_ARG_VALUE',
266+
});
258267

259-
dns.lookup('', {
260-
hints: dns.ADDRCONFIG | dns.V4MAPPED
261-
}, common.mustCall());
268+
assert.throws(() => {
269+
dns.lookup('', {
270+
hints: dns.ADDRCONFIG | dns.V4MAPPED
271+
}, common.mustNotCall());
272+
}, {
273+
code: 'ERR_INVALID_ARG_VALUE',
274+
});
262275

263-
dns.lookup('', {
264-
hints: dns.ALL
265-
}, common.mustCall());
276+
assert.throws(() => {
277+
dns.lookup('', {
278+
hints: dns.ALL
279+
}, common.mustNotCall());
280+
}, {
281+
code: 'ERR_INVALID_ARG_VALUE',
282+
});
266283

267-
dns.lookup('', {
268-
hints: dns.V4MAPPED | dns.ALL
269-
}, common.mustCall());
284+
assert.throws(() => {
285+
dns.lookup('', {
286+
hints: dns.V4MAPPED | dns.ALL
287+
}, common.mustNotCall());
288+
}, {
289+
code: 'ERR_INVALID_ARG_VALUE',
290+
});
270291

271-
dns.lookup('', {
272-
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
273-
}, common.mustCall());
292+
assert.throws(() => {
293+
dns.lookup('', {
294+
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
295+
}, common.mustNotCall());
296+
}, {
297+
code: 'ERR_INVALID_ARG_VALUE',
298+
});
274299

275-
dns.lookup('', {
276-
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL,
277-
family: 'IPv4'
278-
}, common.mustCall());
300+
assert.throws(() => {
301+
dns.lookup('', {
302+
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL,
303+
family: 'IPv4'
304+
}, common.mustNotCall());
305+
}, {
306+
code: 'ERR_INVALID_ARG_VALUE',
307+
});
279308

280-
dns.lookup('', {
281-
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL,
282-
family: 'IPv6'
283-
}, common.mustCall());
309+
assert.throws(() => {
310+
dns.lookup('', {
311+
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL,
312+
family: 'IPv6'
313+
}, common.mustNotCall());
314+
}, {
315+
code: 'ERR_INVALID_ARG_VALUE',
316+
});
284317

285318
(async function() {
286-
await dnsPromises.lookup('', { family: 4, hints: 0 });
287-
await dnsPromises.lookup('', { family: 6, hints: dns.ADDRCONFIG });
288-
await dnsPromises.lookup('', { hints: dns.V4MAPPED });
289-
await dnsPromises.lookup('', { hints: dns.ADDRCONFIG | dns.V4MAPPED });
290-
await dnsPromises.lookup('', { hints: dns.ALL });
291-
await dnsPromises.lookup('', { hints: dns.V4MAPPED | dns.ALL });
292-
await dnsPromises.lookup('', {
319+
await assert.rejects(dnsPromises.lookup('', { family: 4, hints: 0 }), {
320+
code: 'ERR_INVALID_ARG_VALUE',
321+
});
322+
await assert.rejects(dnsPromises.lookup('', { family: 6, hints: dns.ADDRCONFIG }), {
323+
code: 'ERR_INVALID_ARG_VALUE',
324+
});
325+
await assert.rejects(dnsPromises.lookup('', { hints: dns.V4MAPPED }), {
326+
code: 'ERR_INVALID_ARG_VALUE',
327+
});
328+
await assert.rejects(dnsPromises.lookup('', { hints: dns.ADDRCONFIG | dns.V4MAPPED }), {
329+
code: 'ERR_INVALID_ARG_VALUE',
330+
});
331+
await assert.rejects(dnsPromises.lookup('', { hints: dns.ALL }), {
332+
code: 'ERR_INVALID_ARG_VALUE',
333+
});
334+
await assert.rejects(dnsPromises.lookup('', { hints: dns.V4MAPPED | dns.ALL }), {
335+
code: 'ERR_INVALID_ARG_VALUE',
336+
});
337+
await assert.rejects(dnsPromises.lookup('', {
293338
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
339+
}), {
340+
code: 'ERR_INVALID_ARG_VALUE',
341+
});
342+
await assert.rejects(dnsPromises.lookup('', { order: 'verbatim' }), {
343+
code: 'ERR_INVALID_ARG_VALUE',
294344
});
295-
await dnsPromises.lookup('', { order: 'verbatim' });
296345
})().then(common.mustCall());
297346

298347
{

0 commit comments

Comments
 (0)