Skip to content

Commit

Permalink
fix(url): fix url construction by using a non existant url instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jonluca committed Jan 24, 2025
1 parent 50929bb commit 306de36
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/util/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 306de36

Please sign in to comment.