Skip to content

Commit d1330b6

Browse files
committed
href: replace mailto by string
1 parent 25efba3 commit d1330b6

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/link.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export type RegisteredLinkProps = RegisterLink extends { Link: infer Link }
1818
| Omit<UnpackProps<Link>, "children">
1919
| (Omit<HTMLAnchorProps, "children" | "href"> & {
2020
href:
21-
| `mailto:${string}`
2221
| `//${string}`
2322
| `https://${string}`
2423
| `http://${string}`
25-
| `#${string}`;
24+
| `#${string}`
25+
| `${string}:${string}`;
2626
})
2727
: Omit<HTMLAnchorProps, "children">;
2828

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

78-
mailto: {
79-
if (target === undefined || !target.startsWith("mailto:")) {
80-
break mailto;
81-
}
82-
83-
return <a href={target} {...rest} />;
84-
}
85-
8678
external_links: {
8779
if (
8880
target === undefined ||
@@ -101,6 +93,15 @@ export function setLink(params: { Link: typeof Link }): void {
10193

10294
return <a href={target} {...rest} />;
10395
}
96+
97+
external_actions: {
98+
const regex = /^[^:]+:[^:]+$/;
99+
if (target === undefined || !regex.test(target)) {
100+
break external_actions;
101+
}
102+
103+
return <a href={target} {...rest} />;
104+
}
104105
}
105106

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

0 commit comments

Comments
 (0)