Skip to content

Commit 908476c

Browse files
Update urls.ts
1 parent 4218169 commit 908476c

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

  • src/frontend/src/lib/functions

src/frontend/src/lib/functions/urls.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ export function resolve_partial_path(path: string) {
22
return new URL(path, window.location.href).pathname;
33
}
44

5-
export function strip_trailing_slash(url: string) {
6-
return url.replace(/\/$/, '');
5+
export function strip_trailing_slash(input: string) {
6+
if (!input || input === '/') return input;
7+
8+
// Split off query string and hash
9+
const [path, query = ''] = input.split('?');
10+
const [cleanPath, hash = ''] = path.split('#');
11+
12+
const normalizedPath = cleanPath.replace(/\/+$/, '');
13+
14+
return normalizedPath + (query ? '?' + query : '') + (hash ? '#' + hash : '');
715
}

0 commit comments

Comments
 (0)