From 930e104da3c7a1da8f0096c9e0d1bb323bcd0735 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Mon, 18 Oct 2021 15:55:48 +0300 Subject: [PATCH] fix(git-resolver): git URLs with a colon should work (#3882) ref #2352 --- .changeset/tidy-crabs-argue.md | 5 +++++ packages/git-resolver/src/parsePref.ts | 9 ++++++++- packages/git-resolver/test/index.ts | 14 ++++++++++++++ packages/git-resolver/test/parsePref.test.ts | 9 +++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 .changeset/tidy-crabs-argue.md create mode 100644 packages/git-resolver/test/parsePref.test.ts diff --git a/.changeset/tidy-crabs-argue.md b/.changeset/tidy-crabs-argue.md new file mode 100644 index 0000000000..efcbd4aa59 --- /dev/null +++ b/.changeset/tidy-crabs-argue.md @@ -0,0 +1,5 @@ +--- +"@pnpm/git-resolver": patch +--- + +Git URLs containing a colon should work. diff --git a/packages/git-resolver/src/parsePref.ts b/packages/git-resolver/src/parsePref.ts index cadefb735b..6598802b85 100644 --- a/packages/git-resolver/src/parsePref.ts +++ b/packages/git-resolver/src/parsePref.ts @@ -38,7 +38,7 @@ export default async function parsePref (pref: string): Promise e.replace(/:([^/])/, ':/$1')) + return [front, ...escapedBacks].join('@') +} + function urlToFetchSpec (urlparse: URL) { urlparse.hash = '' const fetchSpec = url.format(urlparse) diff --git a/packages/git-resolver/test/index.ts b/packages/git-resolver/test/index.ts index e79e4d1591..0a55b1ef1f 100644 --- a/packages/git-resolver/test/index.ts +++ b/packages/git-resolver/test/index.ts @@ -259,6 +259,20 @@ test.skip('resolveFromGit() bitbucket with tag', async () => { }) }) +test('resolveFromGit() gitlab with colon in the URL', async () => { + const resolveResult = await resolveFromGit({ pref: 'ssh://git@gitlab:pnpm/git-resolver#988c61e11dc8d9ca0b5580cb15291951812549dc' }) + expect(resolveResult).toStrictEqual({ + id: 'gitlab/pnpm/git-resolver/988c61e11dc8d9ca0b5580cb15291951812549dc', + normalizedPref: 'ssh://git@gitlab:pnpm/git-resolver#988c61e11dc8d9ca0b5580cb15291951812549dc', + resolution: { + commit: '988c61e11dc8d9ca0b5580cb15291951812549dc', + repo: 'ssh://git@gitlab/pnpm/git-resolver', + type: 'git', + }, + resolvedVia: 'git-repository', + }) +}) + test('resolveFromGit() gitlab with commit', async () => { const resolveResult = await resolveFromGit({ pref: 'gitlab:pnpm/git-resolver#988c61e11dc8d9ca0b5580cb15291951812549dc' }) expect(resolveResult).toStrictEqual({ diff --git a/packages/git-resolver/test/parsePref.test.ts b/packages/git-resolver/test/parsePref.test.ts new file mode 100644 index 0000000000..b2e4239bbf --- /dev/null +++ b/packages/git-resolver/test/parsePref.test.ts @@ -0,0 +1,9 @@ +import parsePref from '@pnpm/git-resolver/lib/parsePref' + +test.each([ + ['ssh://username:password@example.com:repo.git', 'ssh://username:password@example.com/repo.git'], + ['ssh://username:password@example.com:repo/@foo.git', 'ssh://username:password@example.com/repo/@foo.git'], +])('the right colon is escaped', async (input, output) => { + const parsed = await parsePref(input) + expect(parsed?.fetchSpec).toBe(output) +})