From 306de36c24a08d95d2ede2b36dd395587fa5176f Mon Sep 17 00:00:00 2001 From: JonLuca DeCaro Date: Fri, 24 Jan 2025 10:28:29 -0800 Subject: [PATCH] fix(url): fix url construction by using a non existant url instead --- lib/util/url.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/util/url.ts b/lib/util/url.ts index 96b45220..33f483de 100644 --- a/lib/util/url.ts +++ b/lib/util/url.ts @@ -26,10 +26,11 @@ export const parse = (u: string | URL) => new URL(u); * @returns */ export function resolve(from: string, to: string) { - const fromUrl = new URL(convertPathToPosix(from), "resolve://"); + // we use a non-existent URL to check if its a relative URL + const fromUrl = new URL(convertPathToPosix(from), "https://aaa.nonexistanturl.com"); const resolvedUrl = new URL(convertPathToPosix(to), fromUrl); const endSpaces = to.match(/(\s*)$/)?.[1] || ""; - if (resolvedUrl.protocol === "resolve:") { + if (resolvedUrl.hostname === "aaa.nonexistanturl.com") { // `from` is a relative URL. const { pathname, search, hash } = resolvedUrl; return pathname + search + hash + endSpaces;