mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-27 18:30:54 +08:00
The Services tab wrote the stored asset URL into href with no scheme check. A javascript: or data: value stored via insert_assets or the asset API became a clickable link. Non-http(s) URLs now render as text.
19 lines
496 B
TypeScript
19 lines
496 B
TypeScript
// httpHref returns raw when it is an http(s) URL, otherwise undefined.
|
|
// Asset URLs are operator/target-supplied; javascript: and data: must not
|
|
// become href values.
|
|
export function httpHref(raw: string | undefined | null): string | undefined {
|
|
const s = (raw ?? "").trim();
|
|
if (!s) {
|
|
return undefined;
|
|
}
|
|
try {
|
|
const u = new URL(s);
|
|
if (u.protocol === "http:" || u.protocol === "https:") {
|
|
return u.href;
|
|
}
|
|
} catch {
|
|
// not a URL
|
|
}
|
|
return undefined;
|
|
}
|