Skip to content

Commit

Permalink
Merge pull request #239 from codegouvfr/href-external-actions
Browse files Browse the repository at this point in the history
href: replace mailto by string
  • Loading branch information
garronej authored Mar 4, 2024
2 parents 25efba3 + 89c3f5c commit 9ae9cc5
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ export type RegisteredLinkProps = RegisterLink extends { Link: infer Link }
?
| Omit<UnpackProps<Link>, "children">
| (Omit<HTMLAnchorProps, "children" | "href"> & {
href:
| `mailto:${string}`
| `//${string}`
| `https://${string}`
| `http://${string}`
| `#${string}`;
href: string;
})
: Omit<HTMLAnchorProps, "children">;

Expand Down Expand Up @@ -75,14 +70,6 @@ export function setLink(params: { Link: typeof Link }): void {
return <button {...rest} className={cx(fr.cx("fr-link"), rest.className)} />;
}

mailto: {
if (target === undefined || !target.startsWith("mailto:")) {
break mailto;
}

return <a href={target} {...rest} />;
}

external_links: {
if (
target === undefined ||
Expand All @@ -101,6 +88,16 @@ export function setLink(params: { Link: typeof Link }): void {

return <a href={target} {...rest} />;
}

uri_scheme: {
// Check if the 'target' starts with a valid URI scheme (e.g., 'mailto:', 'tel:', 'skype:', 'facetime:', etc.)
const regex = /^[a-z]+:/;
if (target === undefined || !regex.test(target)) {
break uri_scheme;
}

return <a href={target} {...rest} />;
}
}

return <params.Link {...props} />;
Expand Down

0 comments on commit 9ae9cc5

Please sign in to comment.