diff --git a/server/utils/parse-package-params.ts b/server/utils/parse-package-params.ts index 4eb44f91f3..30f111ce1b 100644 --- a/server/utils/parse-package-params.ts +++ b/server/utils/parse-package-params.ts @@ -6,7 +6,12 @@ export function parsePackageParams(segments: string[]): { rawPackageName: string rawVersion: string | undefined } { - const vIndex = segments.indexOf('v') + let vIndex = segments.indexOf('v') + + // If we encounter ".../v/v/...", treat the second "v" as the version delimiter. + if (segments[vIndex] === 'v' && segments[vIndex + 1] === 'v') { + vIndex++ + } if (vIndex !== -1 && vIndex < segments.length - 1) { return { diff --git a/shared/utils/parse-package-param.ts b/shared/utils/parse-package-param.ts index ef58da1727..310fcd2fd0 100644 --- a/shared/utils/parse-package-param.ts +++ b/shared/utils/parse-package-param.ts @@ -37,7 +37,12 @@ export interface ParsedPackageParams { */ export function parsePackageParam(pkgParam: string): ParsedPackageParams { const segments = pkgParam.split('/') - const vIndex = segments.indexOf('v') + let vIndex = segments.indexOf('v') + + // If we encounter ".../v/v/...", treat the second "v" as the version delimiter. + if (segments[vIndex] === 'v' && segments[vIndex + 1] === 'v') { + vIndex++ + } if (vIndex !== -1 && vIndex < segments.length - 1) { return { diff --git a/test/unit/server/utils/parse-package-params.spec.ts b/test/unit/server/utils/parse-package-params.spec.ts index f020f70680..e1e3be5a9c 100644 --- a/test/unit/server/utils/parse-package-params.spec.ts +++ b/test/unit/server/utils/parse-package-params.spec.ts @@ -49,5 +49,14 @@ describe('parsePackageParams', () => { rawVersion: '1.0.0', }) }) + + it('parses scoped package names whose package segment is literally v', () => { + const segments = ['@scope', 'v', 'v', '1.2.3'] + const result = parsePackageParams(segments) + expect(result).toEqual({ + rawPackageName: '@scope/v', + rawVersion: '1.2.3', + }) + }) }) }) diff --git a/test/unit/shared/utils/parse-package-param.spec.ts b/test/unit/shared/utils/parse-package-param.spec.ts index c827c5e589..dbf2223082 100644 --- a/test/unit/shared/utils/parse-package-param.spec.ts +++ b/test/unit/shared/utils/parse-package-param.spec.ts @@ -85,6 +85,15 @@ describe('parsePackageParam', () => { rest: [], }) }) + + it('parses scoped package names whose package segment is literally v', () => { + const result = parsePackageParam('@scope/v/v/1.2.3/dist/index.js') + expect(result).toEqual({ + packageName: '@scope/v', + version: '1.2.3', + rest: ['dist', 'index.js'], + }) + }) }) describe('edge cases', () => {