Skip to content

Commit

Permalink
fix: all relative url behaviour is as expected now;
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Aug 13, 2024
1 parent f32bd6e commit dc99eb7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/core/src/RequestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export function normalizeUrl(url: string | String | URL, allowRelativeUrls: bool
return new URL(primitiveUrl, 'http://dummy').href.replace(/^[a-z]+:/, '');
}

if ('location' in globalThis || allowRelativeUrls) {
if ('location' in globalThis) {
if (primitiveUrl.startsWith('/')) {
return `${globalThis.location.origin}${primitiveUrl}`;
} else {
return `${globalThis.location.href}/${primitiveUrl}`;
}
} else if (allowRelativeUrls) {
const urlInstance = new URL(primitiveUrl, 'http://dummy');
return urlInstance.pathname + urlInstance.search;
} else {
Expand Down

0 comments on commit dc99eb7

Please sign in to comment.