Fix at escaping

This commit is contained in:
Justin Hutchings
2022-10-04 15:14:04 -07:00
parent e85ff37e44
commit ff12a16459
3 changed files with 37 additions and 5 deletions

20
dist/index.js generated vendored
View File

@@ -21883,8 +21883,13 @@ function getManifestFromSpdxFile(document, fileName) {
let purl = pkg.externalRefs?.find(ref => ref.referenceCategory === "PACKAGE-MANAGER" && ref.referenceType === "purl")?.referenceLocator;
if (purl == null || purl == undefined) {
purl = `pkg:generic/${packageName}@${packageVersion}`;
}
purl = decodeURIComponent(purl);
} else {
// Working around weird encoding issues from an SBOM generator
// Find the last instance of %40 and replace it with @
purl = replaceVersionEscape(purl);
}
let relationships = document.relationships?.find(rel => rel.relatedSpdxElement == pkg.SPDXID && rel.relationshipType == "DEPENDS_ON" && rel.spdxElementId != "SPDXRef-RootPackage");
if (relationships != null && relationships.length > 0) {
@@ -21913,6 +21918,17 @@ function searchFiles() {
return glob.sync(`${filePath}/${filePattern}`, {});
}
// Fixes issues with an escaped version string
function replaceVersionEscape(purl) {
if (!purl.includes("@")) {
let index = purl.lastIndexOf("%40");
if (index > 0) {
purl = purl.substring(0, index) + "@" + purl.substring(index + 3);
}
}
return purl;
}
run();
})();

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -46,8 +46,13 @@ function getManifestFromSpdxFile(document, fileName) {
let purl = pkg.externalRefs?.find(ref => ref.referenceCategory === "PACKAGE-MANAGER" && ref.referenceType === "purl")?.referenceLocator;
if (purl == null || purl == undefined) {
purl = `pkg:generic/${packageName}@${packageVersion}`;
}
purl = decodeURIComponent(purl);
} else {
// Working around weird encoding issues from an SBOM generator
// Find the last instance of %40 and replace it with @
purl = replaceVersionEscape(purl);
}
let relationships = document.relationships?.find(rel => rel.relatedSpdxElement == pkg.SPDXID && rel.relationshipType == "DEPENDS_ON" && rel.spdxElementId != "SPDXRef-RootPackage");
if (relationships != null && relationships.length > 0) {
@@ -76,4 +81,15 @@ function searchFiles() {
return glob.sync(`${filePath}/${filePattern}`, {});
}
// Fixes issues with an escaped version string
function replaceVersionEscape(purl) {
if (!purl.includes("@")) {
let index = purl.lastIndexOf("%40");
if (index > 0) {
purl = purl.substring(0, index) + "@" + purl.substring(index + 3);
}
}
return purl;
}
run();