◐ Shell
clean mode source ↗

http: trim off brackets from IPv6 addresses with string operations · nodejs/node@b4a23d6

Original file line numberDiff line numberDiff line change

@@ -112,7 +112,9 @@ class ProxyConfig {

112112

const { host, hostname, port, protocol, username, password } = new URL(proxyUrl);

113113

this.href = proxyUrl; // Full URL of the proxy server.

114114

this.host = host; // Full host including port, e.g. 'localhost:8080'.

115-

this.hostname = hostname.replace(/^\[|\]$/g, ''); // Trim off the brackets from IPv6 addresses.

115+

// Trim off the brackets from IPv6 addresses. As it's parsed from a valid URL, an opening

116+

// "[" Must already have a matching "]" at the end.

117+

this.hostname = hostname[0] === '[' ? hostname.slice(1, -1) : hostname;

116118

this.port = port ? NumberParseInt(port, 10) : (protocol === 'https:' ? 443 : 80);

117119

this.protocol = protocol; // Protocol of the proxy server, e.g. 'http:' or 'https:'.

118120