Skip to content

Commit 613b504

Browse files
committed
fixup! fix(@angular/ssr): preserve trailing slashes in query and fragment of redirect URLs
1 parent 4e80e2e commit 613b504

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

  • packages/angular/ssr/src/utils

‎packages/angular/ssr/src/utils/url.ts‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,8 @@ export function addTrailingSlash(url: string): string {
100100
export 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

0 commit comments

Comments
 (0)