Skip to content

Commit ff12a16

Browse files
committed
Fix at escaping
1 parent e85ff37 commit ff12a16

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

dist/index.js

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ function getManifestFromSpdxFile(document, fileName) {
4646
let purl = pkg.externalRefs?.find(ref => ref.referenceCategory === "PACKAGE-MANAGER" && ref.referenceType === "purl")?.referenceLocator;
4747
if (purl == null || purl == undefined) {
4848
purl = `pkg:generic/${packageName}@${packageVersion}`;
49-
}
50-
purl = decodeURIComponent(purl);
49+
} else {
50+
// Working around weird encoding issues from an SBOM generator
51+
// Find the last instance of %40 and replace it with @
52+
purl = replaceVersionEscape(purl);
53+
}
54+
55+
5156

5257
let relationships = document.relationships?.find(rel => rel.relatedSpdxElement == pkg.SPDXID && rel.relationshipType == "DEPENDS_ON" && rel.spdxElementId != "SPDXRef-RootPackage");
5358
if (relationships != null && relationships.length > 0) {
@@ -76,4 +81,15 @@ function searchFiles() {
7681
return glob.sync(`${filePath}/${filePattern}`, {});
7782
}
7883

84+
// Fixes issues with an escaped version string
85+
function replaceVersionEscape(purl) {
86+
if (!purl.includes("@")) {
87+
let index = purl.lastIndexOf("%40");
88+
if (index > 0) {
89+
purl = purl.substring(0, index) + "@" + purl.substring(index + 3);
90+
}
91+
}
92+
return purl;
93+
}
94+
7995
run();

0 commit comments

Comments
 (0)