File tree Expand file tree Collapse file tree
packages/angular/ssr/src/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -100,14 +100,8 @@ export function addTrailingSlash(url: string): string {
100100export function joinUrlParts ( ...parts : string [ ] ) : string {
101101 const normalizedParts : string [ ] = [ ] ;
102102 let suffix = '' ;
103- let len = parts . length ;
104103
105- while ( len > 0 && parts [ len - 1 ] === '' ) {
106- len -- ;
107- }
108-
109- for ( let i = 0 ; i < len ; i ++ ) {
110- const part = parts [ i ] ;
104+ for ( const part of parts ) {
111105 if ( part === '' ) {
112106 // Skip any empty parts
113107 continue ;
@@ -116,15 +110,18 @@ export function joinUrlParts(...parts: string[]): string {
116110 let start = 0 ;
117111 let end = part . length ;
118112
119- if ( i === len - 1 ) {
120- const queryIndex = part . indexOf ( '?' ) ;
121- const hashIndex = queryIndex === 0 ? - 1 : part . indexOf ( '#' ) ;
122- const suffixIndex =
123- queryIndex !== - 1 && ( hashIndex === - 1 || queryIndex < hashIndex ) ? queryIndex : hashIndex ;
124- if ( suffixIndex !== - 1 ) {
125- suffix = part . slice ( suffixIndex ) ;
126- end = suffixIndex ;
127- }
113+ const queryIndex = part . indexOf ( '?' ) ;
114+ const hashIndex = part . indexOf ( '#' ) ;
115+ const suffixIndex =
116+ queryIndex === - 1
117+ ? hashIndex
118+ : hashIndex === - 1
119+ ? queryIndex
120+ : Math . min ( queryIndex , hashIndex ) ;
121+
122+ if ( suffixIndex !== - 1 ) {
123+ suffix = part . slice ( suffixIndex ) ;
124+ end = suffixIndex ;
128125 }
129126
130127 // Use "Pointers" to avoid intermediate slices
You can’t perform that action at this time.
0 commit comments