Skip to content

Commit

Permalink
fix link tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Mar 26, 2024
1 parent 32cc517 commit 303e974
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/ui/app/src/components/FernLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ export function checkIsRelativeUrl(url: UrlObject): boolean {
}

if (url.href == null) {
return false;
return true;
}

if (url.href.startsWith("/")) {
return false;
}

return url.href == null || url.href.startsWith(".") || url.href?.startsWith("#") || url.href?.startsWith("?");
return (
url.href.startsWith(".") || url.href.startsWith("#") || url.href.startsWith("?") || !url.href.startsWith("/")
);
}
6 changes: 3 additions & 3 deletions packages/ui/app/src/components/__test__/FernLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ describe("checkIsRelativeUrl", () => {
expect(checkIsRelativeUrl(toUrlObject("../../path"))).toBe(true);
expect(checkIsRelativeUrl(toUrlObject("./path"))).toBe(true);
expect(checkIsRelativeUrl({})).toBe(true);
expect(checkIsRelativeUrl(toUrlObject("#hash"))).toBe(true);
expect(checkIsRelativeUrl(toUrlObject("#"))).toBe(true);
expect(checkIsRelativeUrl(toUrlObject("?search"))).toBe(true);
});

it("returns false for absolute URLs", () => {
expect(checkIsRelativeUrl(toUrlObject("/path"))).toBe(false);
expect(checkIsRelativeUrl(toUrlObject("/#"))).toBe(false);
expect(checkIsRelativeUrl(toUrlObject("#hash"))).toBe(false);
expect(checkIsRelativeUrl(toUrlObject("#"))).toBe(false);
expect(checkIsRelativeUrl(toUrlObject("?search"))).toBe(false);
});

it("returns false for external URLs", () => {
Expand Down

0 comments on commit 303e974

Please sign in to comment.