fix: Internal URL detection on client, closes #7245

This commit is contained in:
Tom Moor
2024-09-14 11:46:42 -04:00
parent e6ba84e434
commit 5116147ace
2 changed files with 7 additions and 1 deletions

View File

@@ -59,6 +59,10 @@ describe("isInternalUrl", () => {
expect(urlsUtils.isInternalUrl("https://example.com:4000")).toBe(false);
});
it("should return false if port is missing", () => {
expect(urlsUtils.isInternalUrl("https://example.com")).toBe(false);
});
it("should return true if starting with relative path", () => {
expect(urlsUtils.isInternalUrl("/drafts")).toEqual(true);
});

View File

@@ -37,7 +37,9 @@ export function isInternalUrl(href: string) {
return (
(outline.host === domain.host && outline.port === domain.port) ||
(typeof window !== "undefined" && window.location.hostname === domain.host)
(typeof window !== "undefined" &&
window.location.hostname === domain.host &&
window.location.port === domain.port)
);
}