diff --git a/shared/utils/git-providers.ts b/shared/utils/git-providers.ts index cf1277fa53..803fc6e134 100644 --- a/shared/utils/git-providers.ts +++ b/shared/utils/git-providers.ts @@ -296,7 +296,7 @@ export function normalizeGitUrl(input: string): string | null { const url = input .trim() .replace(/^git\+/, '') - .replace(/\.git$/, '') + .replace(/\.git(?=[/#?]|$)/i, '') .replace(/(^|\/)[^/]+?@/, '$1') // remove "user@" from "ssh://user@host.com:..." .replace(/(\.[^./]+?):/, '$1/') // change ".com:" to ".com/" from "ssh://user@host.com:..." .replace(/^git:\/\//, 'https://') diff --git a/test/unit/shared/utils/git-providers.spec.ts b/test/unit/shared/utils/git-providers.spec.ts index 4b6b5dbad3..e4c6e3c5d4 100644 --- a/test/unit/shared/utils/git-providers.spec.ts +++ b/test/unit/shared/utils/git-providers.spec.ts @@ -38,6 +38,12 @@ describe('normalizeGitUrl', () => { expect .soft(normalizeGitUrl('https://bitbucket.org/user/repo.git')) .toBe('https://bitbucket.org/user/repo') + expect + .soft(normalizeGitUrl('git+https://github.com/user/repo.git#readme')) + .toBe('https://github.com/user/repo#readme') + expect + .soft(normalizeGitUrl('git+https://github.com/user/repo.git?path=packages/core')) + .toBe('https://github.com/user/repo?path=packages/core') }) it('should convert git:// protocol to https://', () => {