diff --git a/shared/utils/urls.test.ts b/shared/utils/urls.test.ts index f4638de894..2950a32da3 100644 --- a/shared/utils/urls.test.ts +++ b/shared/utils/urls.test.ts @@ -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); }); diff --git a/shared/utils/urls.ts b/shared/utils/urls.ts index 7079bea47a..7e6a5a3c1b 100644 --- a/shared/utils/urls.ts +++ b/shared/utils/urls.ts @@ -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) ); }