| 3 | import { execFileNoThrow } from './execFileNoThrow.js' |
| 4 | |
| 5 | function validateUrl(url: string): void { |
| 6 | let parsedUrl: URL |
| 7 | |
| 8 | try { |
| 9 | parsedUrl = new URL(url) |
| 10 | } catch (_error) { |
| 11 | throw new Error(`Invalid URL format: ${url}`) |
| 12 | } |
| 13 | |
| 14 | // Validate URL protocol for security |
| 15 | if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') { |
| 16 | throw new Error( |
| 17 | `Invalid URL protocol: must use http:// or https://, got ${parsedUrl.protocol}`, |
| 18 | ) |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Open a file or folder path using the system's default handler. |