Skip to content

Commit

Permalink
fix: escape a colon in tarbal dependency ID (#3183)
Browse files Browse the repository at this point in the history
close #3182
  • Loading branch information
zkochan committed Feb 22, 2021
1 parent 08039f3 commit 9928201
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/unlucky-sheep-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pnpm/tarball-resolver": patch
---

The ID of a tarball dependency should not contain colons, when the URL has a port. The colon should be escaped with a plus sign.
2 changes: 1 addition & 1 deletion packages/tarball-resolver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async function resolveTarball (
if (isRepository(wantedDependency.pref)) return null

return {
id: `@${wantedDependency.pref.replace(/^.*:\/\/(git@)?/, '')}`,
id: `@${wantedDependency.pref.replace(/^.*:\/\/(git@)?/, '').replace(':', '+')}`,
normalizedPref: wantedDependency.pref,
resolution: {
tarball: wantedDependency.pref,
Expand Down
13 changes: 13 additions & 0 deletions packages/tarball-resolver/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ test('tarball from npm registry', async () => {
})
})

test('tarball from URL that contain port number', async () => {
const resolutionResult = await resolveFromTarball({ pref: 'http://buildserver.mycompany.com:81/my-private-package-0.1.6.tgz' })

expect(resolutionResult).toStrictEqual({
id: '@buildserver.mycompany.com+81/my-private-package-0.1.6.tgz',
normalizedPref: 'http://buildserver.mycompany.com:81/my-private-package-0.1.6.tgz',
resolution: {
tarball: 'http://buildserver.mycompany.com:81/my-private-package-0.1.6.tgz',
},
resolvedVia: 'url',
})
})

test('tarball not from npm registry', async () => {
const resolutionResult = await resolveFromTarball({ pref: 'https://github.com/hegemonic/taffydb/tarball/master' })

Expand Down

0 comments on commit 9928201

Please sign in to comment.