From fe5ac2719a4b2128318e33187c2e657b2360de25 Mon Sep 17 00:00:00 2001 From: Basile Spaenlehauer Date: Mon, 9 Dec 2024 11:03:56 +0100 Subject: [PATCH] fix: add try catch on new URL that might fail (#1135) --- src/items/LinkItem.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/items/LinkItem.tsx b/src/items/LinkItem.tsx index 9b7495277..e84d21921 100644 --- a/src/items/LinkItem.tsx +++ b/src/items/LinkItem.tsx @@ -23,6 +23,14 @@ const StyledIFrame = styled('iframe')<{ height: !isResizable ? height : '100%', })); +function isURLExternal(url: string): boolean { + try { + return new URL(url).origin !== window.location.origin; + } catch { + return false; + } +} + type LinkItemProps = { /** * Id of the component used for testing @@ -173,7 +181,7 @@ const LinkItem = ({ return {errorMessage}; } - const isExternal = new URL(url).origin !== window.location.origin; + const isExternal = isURLExternal(url); const linkCard = (