Skip to content

Commit

Permalink
Fix for isse #63 - Incorrect parsing of PURL with leading '/' in name…
Browse files Browse the repository at this point in the history
…space
  • Loading branch information
aniruth37 committed Dec 13, 2023
1 parent 06c7d20 commit 11e2aca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/package-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class PackageURL {

let type
[type, remainder] = remainder.split('/', 2);
if (!type || !remainder) {
if (!type) {
throw new Error('purl is missing the required "type" component.');
}
type = decodeURIComponent(type)
Expand Down Expand Up @@ -207,7 +207,7 @@ class PackageURL {
let nameIndex = remaining.length - 1;
let namespaceComponents = remaining.slice(0, nameIndex);
name = decodeURIComponent(remaining[nameIndex]);
namespace = decodeURIComponent(namespaceComponents.join('/'));
namespace = decodeURIComponent(namespaceComponents.filter(item => item.trim()).join('/'));
} else if (remaining.length === 1) {
name = decodeURIComponent(remaining[0]);
}
Expand Down
12 changes: 12 additions & 0 deletions test/data/test-suite-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -430,5 +430,17 @@
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "In namespace, leading and trailing slashes '/' are not significant and should be stripped in the canonical form",
"purl": "pkg:golang//github.com/ll/[email protected]",
"canonical_purl": "pkg:golang/github.com/ll/[email protected]",
"type": "golang",
"namespace": "github.com/ll",
"name": "xlog",
"version": "2.0",
"qualifiers": null,
"subpath": null,
"is_invalid": false
}
]

0 comments on commit 11e2aca

Please sign in to comment.