(url: string | null | undefined)
| 376 | * Only allows http/https protocols, returns '#' for invalid URLs |
| 377 | */ |
| 378 | export function sanitizeUrl(url: string | null | undefined): string { |
| 379 | if (!url) return "#"; |
| 380 | try { |
| 381 | const parsed = new URL(url); |
| 382 | // Only allow http and https protocols |
| 383 | if (parsed.protocol === "http:" || parsed.protocol === "https:") { |
| 384 | return url; |
| 385 | } |
| 386 | } catch { |
| 387 | // Invalid URL |
| 388 | } |
| 389 | return "#"; |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Derive a GitHub @handle from a profile URL |
no outgoing calls
no test coverage detected