fix(git): handle malformed HTTPS+SSH hybrid remote URLs

Some git clients produce malformed URLs that mix HTTPS and SSH formats
(e.g., `https://git@github.com:user/repo`). These URLs would cause
window.open() to fail with an invalid URL error.

Added handling to convert these hybrid URLs to proper HTTPS format.

Fixes MAESTRO-43
This commit is contained in:
Pedram Amini
2026-02-01 09:38:48 -05:00
parent e2fffe2987
commit c2e9efc444
2 changed files with 23 additions and 0 deletions

View File

@@ -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', () => {

View File

@@ -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$/, '');