File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,14 +53,14 @@ export function getProxyForUrl(
5353 noProxyFallback ?: string | null ,
5454) : string {
5555 const parsedUrl = URL . parse ( url ) ;
56- if ( ! parsedUrl ?. host ) {
56+ if ( ! parsedUrl ?. hostname ) {
5757 return "" ; // Don't proxy URLs without a valid scheme or host.
5858 }
5959
60- const proto = parsedUrl . protocol . split ( ":" , 1 ) [ 0 ] ;
61- // Stripping ports in this way instead of using parsedUrl.hostname to make
62- // sure that the brackets around IPv6 addresses are kept .
63- const hostname = parsedUrl . host . replace ( / : \d * $ / , "" ) ;
60+ const proto = parsedUrl . protocol . slice ( 0 , - 1 ) ;
61+ // WHATWG keeps the brackets around IPv6 hosts, so no-proxy entries like
62+ // "[::1]" still match .
63+ const hostname = parsedUrl . hostname ;
6464 const port = Number . parseInt ( parsedUrl . port ) || DEFAULT_PORTS [ proto ] || 0 ;
6565 if ( ! shouldProxy ( hostname , port , noProxy , noProxyFallback ) ) {
6666 return "" ; // Don't proxy URLs that match NO_PROXY.
Original file line number Diff line number Diff line change @@ -98,6 +98,11 @@ describe("proxy", () => {
9898 noProxy : "example.com:8443" ,
9999 url : "https://example.com:8443" ,
100100 } ,
101+ {
102+ name : "bracketed IPv6" ,
103+ noProxy : "[::1]" ,
104+ url : "http://[::1]:8080" ,
105+ } ,
101106 ] ) (
102107 "bypasses proxy when hostname matches noProxy ($name)" ,
103108 ( { noProxy, url } ) => {
You can’t perform that action at this time.
0 commit comments