Skip to content

Commit

Permalink
dns: add deprecation code and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oyyd committed Sep 30, 2018
1 parent 0ae969f commit 197af1c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,22 @@ the `_handle` property of the `Cipher`, `Decipher`, `DiffieHellman`,
Using the `_handle` property to access the native object is deprecated because
improper use of the native object can lead to crashing the application.
<a id="DEP0118"></a>
### DEP0118: dns.lookup supports for falsy hostname
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/23173
description: Runtime deprecation.
-->
Type: Runtime
Previous versions of Node.js support `dns.lookup` a falsy hostname like
`dns.lookup(false)` for the reason of backward compatibility long before.
This behavior is undocumented and seems useless in real world apps. We
might make invalid hostname throw in the future.
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
Expand Down
1 change: 1 addition & 0 deletions lib/internal/dns/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ function emitInvalidHostnameWarning(hostname) {
`The provided hostname "${hostname}" is not a valid ` +
'hostname, and is supported in the dns module solely for compatibility.',
'DeprecationWarning',
'DEP0118'
);
}

Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-dns-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ common.expectWarning({
[
'The provided hostname "false" is not a valid ' +
'hostname, and is supported in the dns module solely for compatibility.',
'DEP0118',
],
[
'The provided hostname "false" is not a valid ' +
'hostname, and is supported in the dns module solely for compatibility.',
'DEP0118',
]
],
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ assert.deepStrictEqual(dns.getServers(), []);
const errorReg = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: /^The "hostname" argument must be one of type string or falsy/
message: /^The "hostname" argument must be of type string\. Received type .*/
}, 10);

assert.throws(() => dns.lookup({}, common.mustNotCall()), errorReg);
Expand Down

0 comments on commit 197af1c

Please sign in to comment.