fix: correct url loss pathname (#9548)

close #9545
This commit is contained in:
btea
2025-05-16 00:30:19 +08:00
committed by Zoltan Kochan
parent c3076344de
commit 505539991f
3 changed files with 9 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/git-resolver": patch
"pnpm": patch
---
Fixed the problem of path loss caused by parsing URL address. Fixes a regression shipped in pnpm v10.11 via [#9502](https://github.com/pnpm/pnpm/pull/9502).

View File

@@ -177,12 +177,12 @@ function correctUrl (gitUrl: string): string {
hash = _gitUrl.slice(hashIndex)
_gitUrl = _gitUrl.slice(0, hashIndex)
}
const [auth, pathname] = _gitUrl.slice(6).split('/')
const [auth, ...pathname] = _gitUrl.slice(6).split('/')
const [, host] = auth.split('@')
if (host.includes(':') && !/:\d+$/.test(host)) {
const authArr = auth.split(':')
const protocol = gitUrl.split('://')[0]
gitUrl = `${protocol}://${authArr.slice(0, -1).join(':') + '/' + authArr[authArr.length - 1]}${pathname ? '/' + pathname : ''}${hash}`
gitUrl = `${protocol}://${authArr.slice(0, -1).join(':') + '/' + authArr[authArr.length - 1]}${pathname.length ? '/' + pathname.join('/') : ''}${hash}`
}
}
return gitUrl

View File

@@ -47,6 +47,7 @@ test.each([
test.each([
['git+https://github.com/pnpm/pnpm.git', 'https://github.com/pnpm/pnpm.git'],
['git+ssh://git@sub.domain.tld:internal-app/sub-path/service-name.git', 'ssh://git@sub.domain.tld/internal-app/sub-path/service-name.git'],
])('the fetchSpec of %s should be %s', async (input, output) => {
const parsed = await parseBareSpecifier(input, {})
expect(parsed?.fetchSpec).toBe(output)