fix: preserve app links and hover previews

This commit is contained in:
Thomas Camlong committed 2026-08-08 21:42:13 +02:00
1 parent 9edeba5cd2
commit f24d757ec8
7 files changed
+47 -13

No files matched your search

+16
View File
@@ -75,6 +75,22 @@ export const getSafeApplicationUrl = (value: unknown, options: SafeApplicationUr
}
};
/** Returns a safe user-configured app link, including same-origin paths and custom URI schemes. */
export const getSafeAppHref = (value: unknown): string | undefined => {
if (typeof value !== "string" || value.trim() === "") return undefined;
const href = value.trim();
if (/^(?:javascript|data|vbscript|file|blob):/i.test(href)) return undefined;
try {
const url = new URL(href);
if (url.username !== "" || url.password !== "") return undefined;
return url.toString();
} catch {
return /^(?:[#?]|\/(?![\\/])|\.{1,2}\/)/.test(href) ? href : undefined;
}
};
const parseHttpUrl = (value: unknown, baseUrl?: string): URL | undefined => {
if (typeof value !== "string") return undefined;
const url = new URL(value, baseUrl);