Skip to content

Commit 8d7931f

Browse files
authored
Update PackageURL.fromString() to handle colon in the package name (#55)
1 parent a98c7fb commit 8d7931f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/package-url.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ class PackageURL {
138138
throw new Error('A purl string argument is required.');
139139
}
140140

141-
let [scheme, remainder] = purl.split(':', 2);
141+
let scheme = purl.slice(0, purl.indexOf(':'))
142+
let remainder = purl.slice(purl.indexOf(':') + 1)
142143
if (scheme !== 'pkg') {
143144
throw new Error('purl is missing the required "pkg" scheme component.');
144145
}

test/data/test-suite-data.json

+12
Original file line numberDiff line numberDiff line change
@@ -418,5 +418,17 @@
418418
"qualifiers": null,
419419
"subpath": null,
420420
"is_invalid": true
421+
},
422+
{
423+
"description": "colon present in name is a valid PURL",
424+
"purl": "pkg:maven/:spring-context@5.2.8-RELEASE",
425+
"canonical_purl": "pkg:maven/:spring-context@5.2.8-RELEASE",
426+
"type": "maven",
427+
"namespace": null,
428+
"name": ":spring-context",
429+
"version": "5.2.8-RELEASE",
430+
"qualifiers": null,
431+
"subpath": null,
432+
"is_invalid": false
421433
}
422434
]

0 commit comments

Comments
 (0)