fix: unicode output in cyclonedx-json format (#1420)

This commit is contained in:
Keith Zantow
2022-12-23 08:37:47 -05:00
committed by GitHub
parent b125ea83ba
commit e1e489a284
18 changed files with 65 additions and 40 deletions
+6 -3
View File
@@ -15,6 +15,7 @@ func TestSPDXJSONDirectoryEncoder(t *testing.T) {
Format(),
testutils.DirectoryInput(t),
*updateSpdxJson,
true,
spdxJsonRedactor,
)
}
@@ -26,6 +27,7 @@ func TestSPDXJSONImageEncoder(t *testing.T) {
testutils.ImageInput(t, testImage, testutils.FromSnapshot()),
testImage,
*updateSpdxJson,
true,
spdxJsonRedactor,
)
}
@@ -39,17 +41,18 @@ func TestSPDXRelationshipOrder(t *testing.T) {
s,
testImage,
*updateSpdxJson,
true,
spdxJsonRedactor,
)
}
func spdxJsonRedactor(s []byte) []byte {
// each SBOM reports the time it was generated, which is not useful during snapshot testing
s = regexp.MustCompile(`"created": .*`).ReplaceAll(s, []byte("redacted"))
s = regexp.MustCompile(`"created":\s+"[^"]*",?`).ReplaceAll(s, []byte(""))
// each SBOM reports a unique documentNamespace when generated, this is not useful for snapshot testing
s = regexp.MustCompile(`"documentNamespace": .*`).ReplaceAll(s, []byte("redacted"))
s = regexp.MustCompile(`"documentNamespace":\s+"[^"]*",?`).ReplaceAll(s, []byte(""))
// the license list will be updated periodically, the value here should not be directly tested in snapshot tests
return regexp.MustCompile(`"licenseListVersion": .*`).ReplaceAll(s, []byte("redacted"))
return regexp.MustCompile(`"licenseListVersion":\s+"[^"]*",?`).ReplaceAll(s, []byte(""))
}