From 5116147aceceab7af91c59ede41f9060e910ee44 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 14 Sep 2024 11:46:42 -0400 Subject: [PATCH] fix: Internal URL detection on client, closes #7245 --- shared/utils/urls.test.ts | 4 ++++ shared/utils/urls.ts | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) 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) ); }