Keep the existing external-scheme boundary and validate authored destinations with the URL constructor before creating a link. A missing HTTPS host now preserves the label. Use the constructor available at the browser build baseline instead of introducing URL.canParse. Validation: the malformed-link regression and the shared chat/release-note suites passed all 12 checks; TypeScript passed. No new URL normalization, protocol or link-fetch behavior was added.
11 lines
279 B
TypeScript
11 lines
279 B
TypeScript
/** Authored content can open ordinary external links, never navigate the App. */
|
|
export function isExternalLink(href: string): boolean {
|
|
if (!/^(?:https?:\/\/|mailto:)/i.test(href)) return false;
|
|
try {
|
|
new URL(href);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|