Skip to content

Commit fa2d43b

Browse files
committed
url: make urlToOptions() handle IPv6 literals
Strip the enclosing square brackets from the parsed hostname. PR-URL: #19720 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent d1156da commit fa2d43b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/internal/url.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,9 @@ function domainToUnicode(domain) {
13141314
function urlToOptions(url) {
13151315
var options = {
13161316
protocol: url.protocol,
1317-
hostname: url.hostname,
1317+
hostname: url.hostname.startsWith('[') ?
1318+
url.hostname.slice(1, -1) :
1319+
url.hostname,
13181320
hash: url.hash,
13191321
search: url.search,
13201322
pathname: url.pathname,

test/parallel/test-whatwg-url-properties.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ assert.strictEqual(url.searchParams, oldParams);
143143
assert.strictEqual(opts.pathname, '/aaa/zzz');
144144
assert.strictEqual(opts.search, '?l=24');
145145
assert.strictEqual(opts.hash, '#test');
146+
147+
const { hostname } = urlToOptions(new URL('http://[::1]:21'));
148+
assert.strictEqual(hostname, '::1');
146149
}
147150

148151
// Test special origins

0 commit comments

Comments
 (0)