Skip to content

Commit ee124d3

Browse files
committed
fix(shared): strip .git before path/query/fragment in normalizeGitUrl
1 parent 1824c62 commit ee124d3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

shared/utils/git-providers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export function normalizeGitUrl(input: string): string | null {
296296
const url = input
297297
.trim()
298298
.replace(/^git\+/, '')
299-
.replace(/\.git$/, '')
299+
.replace(/\.git(?=[/#?]|$)/i, '')
300300
.replace(/(^|\/)[^/]+?@/, '$1') // remove "user@" from "ssh://user@host.com:..."
301301
.replace(/(\.[^./]+?):/, '$1/') // change ".com:" to ".com/" from "ssh://user@host.com:..."
302302
.replace(/^git:\/\//, 'https://')

test/unit/shared/utils/git-providers.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ describe('normalizeGitUrl', () => {
3838
expect
3939
.soft(normalizeGitUrl('https://bitbucket.org/user/repo.git'))
4040
.toBe('https://bitbucket.org/user/repo')
41+
expect
42+
.soft(normalizeGitUrl('git+https://github.com/user/repo.git#readme'))
43+
.toBe('https://github.com/user/repo#readme')
44+
expect
45+
.soft(normalizeGitUrl('git+https://github.com/user/repo.git?path=packages/core'))
46+
.toBe('https://github.com/user/repo?path=packages/core')
4147
})
4248

4349
it('should convert git:// protocol to https://', () => {

0 commit comments

Comments
 (0)