(url: string)
| 123 | * @returns Sanitized URL |
| 124 | */ |
| 125 | export function sanitizeGitUrl(url: string): string { |
| 126 | try { |
| 127 | // Remove credentials from HTTPS URLs |
| 128 | if (url.startsWith("https://")) { |
| 129 | const urlObj = new URL(url) |
| 130 | // Remove username and password |
| 131 | urlObj.username = "" |
| 132 | urlObj.password = "" |
| 133 | return urlObj.toString() |
| 134 | } |
| 135 | |
| 136 | // For SSH URLs, return as-is (they don't contain sensitive tokens) |
| 137 | if (url.startsWith("git@") || url.startsWith("ssh://")) { |
| 138 | return url |
| 139 | } |
| 140 | |
| 141 | // For other formats, return as-is but remove any potential tokens |
| 142 | return url.replace(/:[a-f0-9]{40,}@/gi, "@") |
| 143 | } catch { |
| 144 | // If URL parsing fails, return original (might be SSH format) |
| 145 | return url |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Extracts repository name from a git URL |
no test coverage detected