Skip to content

Commit 306de36

Browse files
committed
fix(url): fix url construction by using a non existant url instead
1 parent 50929bb commit 306de36

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/util/url.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ export const parse = (u: string | URL) => new URL(u);
2626
* @returns
2727
*/
2828
export function resolve(from: string, to: string) {
29-
const fromUrl = new URL(convertPathToPosix(from), "resolve://");
29+
// we use a non-existent URL to check if its a relative URL
30+
const fromUrl = new URL(convertPathToPosix(from), "https://aaa.nonexistanturl.com");
3031
const resolvedUrl = new URL(convertPathToPosix(to), fromUrl);
3132
const endSpaces = to.match(/(\s*)$/)?.[1] || "";
32-
if (resolvedUrl.protocol === "resolve:") {
33+
if (resolvedUrl.hostname === "aaa.nonexistanturl.com") {
3334
// `from` is a relative URL.
3435
const { pathname, search, hash } = resolvedUrl;
3536
return pathname + search + hash + endSpaces;

0 commit comments

Comments
 (0)