diff --git a/src/__tests__/shared/gitUtils.test.ts b/src/__tests__/shared/gitUtils.test.ts index 38bc2276..a159e33d 100644 --- a/src/__tests__/shared/gitUtils.test.ts +++ b/src/__tests__/shared/gitUtils.test.ts @@ -279,6 +279,19 @@ describe('gitUtils', () => { expect(remoteUrlToBrowserUrl('unknown://something')).toBeNull(); expect(remoteUrlToBrowserUrl('just-a-string')).toBeNull(); }); + + it('handles malformed HTTPS+SSH hybrid URLs (MAESTRO-43)', () => { + // Some git clients may produce malformed URLs that mix HTTPS and SSH formats + expect(remoteUrlToBrowserUrl('https://git@github.com:chancegraff/project-aig')).toBe( + 'https://github.com/chancegraff/project-aig' + ); + expect(remoteUrlToBrowserUrl('http://git@github.com:user/repo.git')).toBe( + 'https://github.com/user/repo' + ); + expect(remoteUrlToBrowserUrl('https://git@gitlab.com:org/project.git')).toBe( + 'https://gitlab.com/org/project' + ); + }); }); describe('isImageFile', () => { diff --git a/src/shared/gitUtils.ts b/src/shared/gitUtils.ts index 5d14cb67..db915b17 100644 --- a/src/shared/gitUtils.ts +++ b/src/shared/gitUtils.ts @@ -280,6 +280,16 @@ export function remoteUrlToBrowserUrl(remoteUrl: string): string | null { return url; } + // Handle malformed HTTPS+SSH hybrid: https://git@github.com:user/repo + // This can happen with misconfigured remotes + if (url.match(/^https?:\/\/git@/)) { + url = url + .replace(/^https?:\/\/git@/, 'https://') + .replace(/:([^/])/, '/$1') // Replace SSH-style : with / + .replace(/\.git$/, ''); + return url; + } + // Handle HTTPS format: https://github.com/user/repo.git if (url.startsWith('https://') || url.startsWith('http://')) { url = url.replace(/\.git$/, '');