Skip to content

Commit da9a6ae

Browse files
committed
Accept pnpm id with parens in the version component
1 parent 3ed826c commit da9a6ae

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/package-url.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,14 @@ class PackageURL {
168168
}
169169

170170
let rawVersion
171-
let atSignIndex = pathname.lastIndexOf('@')
172-
// Handle unencoded leading '@' characters. This is a small break from
173-
// the specification to make parsing more forgiving so that users don't
174-
// have to deal with it.
171+
let atSignIndex =
172+
rawType === 'npm'
173+
? // Deviate from the specification to handle a special npm purl type case for
174+
175+
pathname.indexOf('@', firstSlashIndex + 2)
176+
: pathname.lastIndexOf('@')
177+
// When a forward slash ('/') is directly preceding an '@' symbol,
178+
// then the '@' symbol is NOT considered a version separator.
175179
if (
176180
atSignIndex !== -1 &&
177181
pathname.charCodeAt(atSignIndex - 1) === 47 /*'/'*/

test/data/contrib-tests.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,17 @@
142142
"qualifiers": null,
143143
"subpath": null,
144144
"is_invalid": false
145+
},
146+
{
147+
"description": "pnpm ids with parens in the version",
148+
149+
"canonical_purl": "pkg:npm/[email protected](react-dom%4018.3.1(react%4018.3.1))(react%4018.3.1)",
150+
"type": "npm",
151+
"namespace": null,
152+
"name": "next",
153+
154+
"qualifiers": null,
155+
"subpath": null,
156+
"is_invalid": false
145157
}
146158
]

0 commit comments

Comments
 (0)