Skip to content

Commit

Permalink
fix: add try catch on new URL that might fail (#1135)
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh authored Dec 9, 2024
1 parent b01618d commit fe5ac27
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/items/LinkItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -173,7 +181,7 @@ const LinkItem = ({
return <Alert severity='error'>{errorMessage}</Alert>;
}

const isExternal = new URL(url).origin !== window.location.origin;
const isExternal = isURLExternal(url);
const linkCard = (
<LinkCard
id={id}
Expand Down

0 comments on commit fe5ac27

Please sign in to comment.