Skip to content

Commit 9ae9cc5

Browse files
authored
Merge pull request #239 from codegouvfr/href-external-actions
href: replace mailto by string
2 parents 25efba3 + 89c3f5c commit 9ae9cc5

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/link.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ export type RegisteredLinkProps = RegisterLink extends { Link: infer Link }
1717
?
1818
| Omit<UnpackProps<Link>, "children">
1919
| (Omit<HTMLAnchorProps, "children" | "href"> & {
20-
href:
21-
| `mailto:${string}`
22-
| `//${string}`
23-
| `https://${string}`
24-
| `http://${string}`
25-
| `#${string}`;
20+
href: string;
2621
})
2722
: Omit<HTMLAnchorProps, "children">;
2823

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

78-
mailto: {
79-
if (target === undefined || !target.startsWith("mailto:")) {
80-
break mailto;
81-
}
82-
83-
return <a href={target} {...rest} />;
84-
}
85-
8673
external_links: {
8774
if (
8875
target === undefined ||
@@ -101,6 +88,16 @@ export function setLink(params: { Link: typeof Link }): void {
10188

10289
return <a href={target} {...rest} />;
10390
}
91+
92+
uri_scheme: {
93+
// Check if the 'target' starts with a valid URI scheme (e.g., 'mailto:', 'tel:', 'skype:', 'facetime:', etc.)
94+
const regex = /^[a-z]+:/;
95+
if (target === undefined || !regex.test(target)) {
96+
break uri_scheme;
97+
}
98+
99+
return <a href={target} {...rest} />;
100+
}
104101
}
105102

106103
return <params.Link {...props} />;

0 commit comments

Comments
 (0)