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