Skip to content

Commit b4a23d6

Browse files
pckrishnadas88targos
authored andcommitted
http: trim off brackets from IPv6 addresses with string operations
This is simpler than using regular expressions. PR-URL: #59420 Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 027b861 commit b4a23d6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/internal/http.js

Lines changed: 3 additions & 1 deletion
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

0 commit comments

Comments
 (0)