Skip to content

Commit

Permalink
url: make urlToOptions() handle IPv6 literals
Browse files Browse the repository at this point in the history
Strip the enclosing square brackets from the parsed hostname.

PR-URL: nodejs#19720
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
lpinca committed Apr 10, 2018
1 parent d1156da commit fa2d43b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,9 @@ function domainToUnicode(domain) {
function urlToOptions(url) {
var options = {
protocol: url.protocol,
hostname: url.hostname,
hostname: url.hostname.startsWith('[') ?
url.hostname.slice(1, -1) :
url.hostname,
hash: url.hash,
search: url.search,
pathname: url.pathname,
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-whatwg-url-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ assert.strictEqual(url.searchParams, oldParams);
assert.strictEqual(opts.pathname, '/aaa/zzz');
assert.strictEqual(opts.search, '?l=24');
assert.strictEqual(opts.hash, '#test');

const { hostname } = urlToOptions(new URL('http://[::1]:21'));
assert.strictEqual(hostname, '::1');
}

// Test special origins
Expand Down

0 comments on commit fa2d43b

Please sign in to comment.