Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f182b9b

Browse filesBrowse files
aduh95nodejs-github-bot
authored andcommitted
dns: runtime deprecate type coercion of dns.lookup options
PR-URL: #39793 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 7b4e6d4 commit f182b9b
Copy full SHA for f182b9b

File tree

Expand file treeCollapse file tree

5 files changed

+62
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+62
-1
lines changed
Open diff view settings
Collapse file

‎doc/api/deprecations.md‎

Copy file name to clipboardExpand all lines: doc/api/deprecations.md
+4-1Lines changed: 4 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -2789,12 +2789,15 @@ deprecated and should no longer be used.
27892789
### DEP0153: `dns.lookup` and `dnsPromises.lookup` options type coercion
27902790
<!-- YAML
27912791
changes:
2792+
- version: REPLACEME
2793+
pr-url: https://github.com/nodejs/node/pull/39793
2794+
description: Runtime deprecation.
27922795
- version: v16.8.0
27932796
pr-url: https://github.com/nodejs/node/pull/38906
27942797
description: Documentation-only deprecation.
27952798
-->
27962799

2797-
Type: Documentation-only
2800+
Type: Runtime
27982801

27992802
Using a non-nullish non-integer value for `family` option, a non-nullish
28002803
non-number value for `hints` option, a non-nullish non-boolean value for `all`
Collapse file

‎lib/dns.js‎

Copy file name to clipboardExpand all lines: lib/dns.js
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const {
4141
Resolver,
4242
validateHints,
4343
emitInvalidHostnameWarning,
44+
emitTypeCoercionDeprecationWarning,
4445
getDefaultVerbatim,
4546
setDefaultResultOrder,
4647
} = require('internal/dns/utils');
@@ -112,15 +113,29 @@ function lookup(hostname, options, callback) {
112113
validateCallback(callback);
113114

114115
if (options !== null && typeof options === 'object') {
116+
if (options.hints != null && typeof options.hints !== 'number') {
117+
emitTypeCoercionDeprecationWarning();
118+
}
115119
hints = options.hints >>> 0;
120+
if (options.family != null && typeof options.family !== 'number') {
121+
emitTypeCoercionDeprecationWarning();
122+
}
116123
family = options.family >>> 0;
124+
if (options.all != null && typeof options.all !== 'boolean') {
125+
emitTypeCoercionDeprecationWarning();
126+
}
117127
all = options.all === true;
118128
if (typeof options.verbatim === 'boolean') {
119129
verbatim = options.verbatim === true;
130+
} else if (options.verbatim != null) {
131+
emitTypeCoercionDeprecationWarning();
120132
}
121133

122134
validateHints(hints);
123135
} else {
136+
if (options != null && typeof options !== 'number') {
137+
emitTypeCoercionDeprecationWarning();
138+
}
124139
family = options >>> 0;
125140
}
126141
}
Collapse file

‎lib/internal/dns/promises.js‎

Copy file name to clipboardExpand all lines: lib/internal/dns/promises.js
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
validateTimeout,
1515
validateTries,
1616
emitInvalidHostnameWarning,
17+
emitTypeCoercionDeprecationWarning,
1718
getDefaultVerbatim,
1819
} = require('internal/dns/utils');
1920
const { codes, dnsException } = require('internal/errors');
@@ -110,15 +111,29 @@ function lookup(hostname, options) {
110111
if (hostname && typeof hostname !== 'string') {
111112
throw new ERR_INVALID_ARG_TYPE('hostname', 'string', hostname);
112113
} else if (options !== null && typeof options === 'object') {
114+
if (options.hints != null && typeof options.hints !== 'number') {
115+
emitTypeCoercionDeprecationWarning();
116+
}
113117
hints = options.hints >>> 0;
118+
if (options.family != null && typeof options.family !== 'number') {
119+
emitTypeCoercionDeprecationWarning();
120+
}
114121
family = options.family >>> 0;
122+
if (options.all != null && typeof options.all !== 'boolean') {
123+
emitTypeCoercionDeprecationWarning();
124+
}
115125
all = options.all === true;
116126
if (typeof options.verbatim === 'boolean') {
117127
verbatim = options.verbatim === true;
128+
} else if (options.verbatim != null) {
129+
emitTypeCoercionDeprecationWarning();
118130
}
119131

120132
validateHints(hints);
121133
} else {
134+
if (options != null && typeof options !== 'number') {
135+
emitTypeCoercionDeprecationWarning();
136+
}
122137
family = options >>> 0;
123138
}
124139

Collapse file

‎lib/internal/dns/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/dns/utils.js
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ function emitInvalidHostnameWarning(hostname) {
193193
);
194194
}
195195

196+
let typeCoercionWarningEmitted = false;
197+
function emitTypeCoercionDeprecationWarning() {
198+
if (!typeCoercionWarningEmitted) {
199+
process.emitWarning(
200+
'Type coercion of dns.lookup options is deprecated',
201+
'DeprecationWarning',
202+
'DEP0153'
203+
);
204+
typeCoercionWarningEmitted = true;
205+
}
206+
}
207+
196208
let dnsOrder = getOptionValue('--dns-result-order') || 'verbatim';
197209

198210
function getDefaultVerbatim() {
@@ -213,6 +225,7 @@ module.exports = {
213225
validateTries,
214226
Resolver,
215227
emitInvalidHostnameWarning,
228+
emitTypeCoercionDeprecationWarning,
216229
getDefaultVerbatim,
217230
setDefaultResultOrder,
218231
};
Collapse file

‎test/internet/test-dns-lookup.js‎

Copy file name to clipboardExpand all lines: test/internet/test-dns-lookup.js
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,18 @@ dns.lookup(addresses.NOT_FOUND, {
4444
assert.strictEqual(error.syscall, 'getaddrinfo');
4545
assert.strictEqual(error.hostname, addresses.NOT_FOUND);
4646
}));
47+
48+
common.expectWarning('DeprecationWarning',
49+
'Type coercion of dns.lookup options is deprecated',
50+
'DEP0153');
51+
52+
assert.rejects(
53+
dnsPromises.lookup(addresses.NOT_FOUND, {
54+
family: 'IPv4',
55+
all: 'all'
56+
}),
57+
{
58+
code: 'ENOTFOUND',
59+
message: `getaddrinfo ENOTFOUND ${addresses.NOT_FOUND}`
60+
}
61+
);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.