url: make urlToOptions() handle IPv6 literals
Strip the enclosing square brackets from the parsed hostname. PR-URL: https://github.com/nodejs/node/pull/19720 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
d1156da815
commit
fa2d43bd3e
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user