Skip to content

Commit

Permalink
feat: validate versions to ensure they dont begin with special charac…
Browse files Browse the repository at this point in the history
…ters (#47)

Signed-off-by: Topaz Turkenitz <[email protected]>
  • Loading branch information
topaztee authored Sep 5, 2023
1 parent 3e0e106 commit 58026c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/package-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ class PackageURL {
if (path.includes('@')) {
let index = path.indexOf('@');
version = decodeURIComponent(path.substring(index + 1));

// Check that version doesnt contain special characters by checking if first char can be encoded
let tempEncoded = encodeURIComponent(version[0]);
let tempDecoded = decodeURIComponent(version[0]);

if (tempDecoded !== tempEncoded) {
throw new Error('Invalid purl: version should not include special characters');
}
remainder = path.substring(0, index);
} else {
remainder = path;
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 @@ -370,5 +370,17 @@
"qualifiers": null,
"subpath": null,
"is_invalid": false
},
{
"description": "invalid maven purl",
"purl": "pkg:maven/org.apache.commons/io@@1.4.0",
"canonical_purl": "pkg:maven/org.apache.commons/io@@1.4.0",
"type": null,
"namespace": null,
"name": "io",
"version": null,
"qualifiers": null,
"subpath": null,
"is_invalid": true
}
]

0 comments on commit 58026c8

Please sign in to comment.