Spaces:
Sleeping
Sleeping
Download src/lib/url.ts from ashnhash/UniHunt: direct link, hf CLI and curl.
- Browser
- Download file 710 Bytes
-
https://huggingface.co/spaces/ashnhash/UniHunt/resolve/main/src/lib/url.ts
- Command line
-
hf download hf://spaces/ashnhash/UniHunt/src/lib/url.ts
-
curl -L -o url.ts https://huggingface.co/spaces/ashnhash/UniHunt/resolve/main/src/lib/url.ts
710 Bytes
| /** | |
| * Course URLs originate from Brave Search, model output, and manual user entry, | |
| * and are rendered straight into an anchor `href`. Restricting them to http(s) | |
| * keeps `javascript:` and `data:` URLs from becoming a click-to-execute vector. | |
| */ | |
| export function isHttpUrl(value: string): boolean { | |
| try { | |
| const { protocol } = new URL(value); | |
| return protocol === "http:" || protocol === "https:"; | |
| } catch { | |
| return false; | |
| } | |
| } | |
| /** Returns the URL when it is a usable http(s) link, or an empty string. */ | |
| export function safeHttpUrl(value: unknown): string { | |
| if (typeof value !== "string") return ""; | |
| const trimmed = value.trim(); | |
| return trimmed && isHttpUrl(trimmed) ? trimmed : ""; | |
| } | |