Skip to content

Commit 3c23a6d

Browse files
bnoordhuistreysis
authored andcommitted
dns: default to verbatim=true in dns.lookup()
Switch the default from false (reorder the result so that IPv4 addresses come before IPv6 addresses) to true (return them exactly as the resolver sent them to us.) Fixes: nodejs#31566 Refs: nodejs#6307 Refs: nodejs#20710 Reissue of nodejs#31567
1 parent 853086f commit 3c23a6d

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

doc/api/dns.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ section if a custom port is used.
163163
<!-- YAML
164164
added: v0.1.90
165165
changes:
166+
- version: REPLACEME
167+
pr-url: https://github.com/nodejs/node/pull/37681
168+
description: The `verbatim` options defaults to `true` now.
166169
- version: v8.5.0
167170
pr-url: https://github.com/nodejs/node/pull/14731
168171
description: The `verbatim` option is supported now.
@@ -183,9 +186,7 @@ changes:
183186
* `verbatim` {boolean} When `true`, the callback receives IPv4 and IPv6
184187
addresses in the order the DNS resolver returned them. When `false`,
185188
IPv4 addresses are placed before IPv6 addresses.
186-
**Default:** currently `false` (addresses are reordered) but this is
187-
expected to change in the not too distant future.
188-
New code should use `{ verbatim: true }`.
189+
**Default:** `true`.
189190
* `callback` {Function}
190191
* `err` {Error}
191192
* `address` {string} A string representation of an IPv4 or IPv6 address.

lib/dns.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function lookup(hostname, options, callback) {
9696
let hints = 0;
9797
let family = -1;
9898
let all = false;
99-
let verbatim = false;
99+
let verbatim = true;
100100

101101
// Parse arguments
102102
if (hostname) {
@@ -113,7 +113,7 @@ function lookup(hostname, options, callback) {
113113
hints = options.hints >>> 0;
114114
family = options.family >>> 0;
115115
all = options.all === true;
116-
verbatim = options.verbatim === true;
116+
verbatim = options.verbatim !== false;
117117

118118
validateHints(hints);
119119
} else {

lib/internal/dns/promises.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function lookup(hostname, options) {
103103
var hints = 0;
104104
var family = -1;
105105
var all = false;
106-
var verbatim = false;
106+
var verbatim = true;
107107

108108
// Parse arguments
109109
if (hostname && typeof hostname !== 'string') {
@@ -112,7 +112,7 @@ function lookup(hostname, options) {
112112
hints = options.hints >>> 0;
113113
family = options.family >>> 0;
114114
all = options.all === true;
115-
verbatim = options.verbatim === true;
115+
verbatim = options.verbatim !== false;
116116

117117
validateHints(hints);
118118
} else {

test/sequential/test-net-better-error-messages-port.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ c.on('connect', common.mustNotCall());
1010
c.on('error', common.mustCall(function(e) {
1111
assert.strictEqual(e.code, 'ECONNREFUSED');
1212
assert.strictEqual(e.port, common.PORT);
13-
assert.strictEqual(e.address, '127.0.0.1');
13+
assert.match(e.address, '/^127\.0\.0\.1$|^::1$/');
1414
}));

0 commit comments

Comments
 (0)