(url: string)
| 55 | * if you want to reject malformed URLs. |
| 56 | */ |
| 57 | export function sanitizeGitUrl(url: string): string { |
| 58 | const sshMatch = url.match(/^git@([^:]+):(.+)$/); |
| 59 | if (sshMatch) { |
| 60 | const host = sshMatch[1]; |
| 61 | const path = sshMatch[2].split('?')[0]; |
| 62 | return `git@${host}:${path}`; |
| 63 | } |
| 64 | |
| 65 | try { |
| 66 | const parsed = new URL(url); |
| 67 | parsed.username = ''; |
| 68 | parsed.password = ''; |
| 69 | parsed.search = ''; |
| 70 | parsed.hash = ''; |
| 71 | return parsed.toString(); |
| 72 | } catch { |
| 73 | return url; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Parse a git URL into platform/owner/repo coordinates. Supports HTTPS and |
no test coverage detected