* Validate a git URL using Node.js URL parsing
(url: string)
| 468 | * Validate a git URL using Node.js URL parsing |
| 469 | */ |
| 470 | function validateGitUrl(url: string): string { |
| 471 | try { |
| 472 | const parsed = new URL(url) |
| 473 | if (!['https:', 'http:', 'file:'].includes(parsed.protocol)) { |
| 474 | if (!/^git@[a-zA-Z0-9.-]+:/.test(url)) { |
| 475 | throw new Error( |
| 476 | `Invalid git URL protocol: ${parsed.protocol}. Only HTTPS, HTTP, file:// and SSH (git@) URLs are supported.`, |
| 477 | ) |
| 478 | } |
| 479 | } |
| 480 | return url |
| 481 | } catch { |
| 482 | if (/^git@[a-zA-Z0-9.-]+:/.test(url)) { |
| 483 | return url |
| 484 | } |
| 485 | throw new Error(`Invalid git URL: ${url}`) |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | /** |
| 490 | * Install a plugin from npm using a global cache (exported for testing) |
no outgoing calls
no test coverage detected