mirror of
https://github.com/jlengrand/Maestro.git
synced 2026-03-10 08:31:19 +00:00
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:
@@ -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', () => {
|
||||
|
||||
@@ -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$/, '');
|
||||
|
||||
Reference in New Issue
Block a user