@@ -28,17 +28,14 @@ export { isLoopbackHost };
2828function hasRawExplicitPort ( raw : string ) : boolean {
2929 // Strip scheme (e.g. "http://") and take only the authority portion
3030 // (everything before the first /, ?, or #).
31- const authority =
32- raw
33- . replace ( / ^ [ a - z ] [ a - z 0 - 9 + . - ] * : \/ \/ / i, "" )
34- . split ( / [ / ? # ] / , 1 ) [ 0 ] ?? "" ;
31+ const authority = raw . replace ( / ^ [ a - z ] [ a - z 0 - 9 + . - ] * : \/ \/ / i, "" ) . split ( / [ / ? # ] / , 1 ) [ 0 ] ?? "" ;
3532
36- // Strip userinfo (user:pass@) — the colon there is NOT a port separator.
33+ // Strip userinfo (user:pass@); the colon there is not a port separator.
3734 const hostPort = authority . includes ( "@" )
3835 ? authority . slice ( authority . lastIndexOf ( "@" ) + 1 )
3936 : authority ;
4037
41- // IPv6: [::1]:9222 → port after closing bracket
38+ // IPv6: [::1]:9222 has a port after the closing bracket.
4239 if ( hostPort . startsWith ( "[" ) ) {
4340 return / ^ \[ [ ^ \] ] + \] : \d + $ / . test ( hostPort ) ;
4441 }
@@ -88,16 +85,15 @@ export function parseBrowserHttpUrl(raw: string, label: string) {
8885 const atIdx = rest . indexOf ( "@" ) ;
8986 const hostStart = atIdx >= 0 ? atIdx + 1 : 0 ;
9087 const hostPart = rest . slice ( hostStart ) ;
91- // Find end of host: IPv6 brackets or first : / /
88+ // Find the end of the host: IPv6 brackets, a path slash, or a port colon.
9289 const hostLen = hostPart . startsWith ( "[" )
9390 ? hostPart . indexOf ( "]" ) + 1
9491 : ( ( ) => {
9592 const idx = hostPart . search ( / [: / ] / ) ;
9693 return idx < 0 ? hostPart . length : idx ;
9794 } ) ( ) ;
9895 const insertAt = hostStart + hostLen ;
99- normalizedWithPort =
100- proto + rest . slice ( 0 , insertAt ) + ":" + port + rest . slice ( insertAt ) ;
96+ normalizedWithPort = proto + rest . slice ( 0 , insertAt ) + ":" + port + rest . slice ( insertAt ) ;
10197 } else {
10298 normalizedWithPort = normalized ;
10399 }
0 commit comments