mirror of
https://github.com/anchore/syft
synced 2024-11-10 14:24:12 +00:00
Fix CycloneDX license decoding panic (#898)
This commit is contained in:
parent
f4734d28b3
commit
99c3339810
2 changed files with 13 additions and 1 deletions
|
@ -272,4 +272,14 @@ func Test_missingDataDecode(t *testing.T) {
|
|||
|
||||
_, err = toSyftModel(bom)
|
||||
assert.NoError(t, err)
|
||||
|
||||
pkg := decodeComponent(&cyclonedx.Component{
|
||||
Licenses: &cyclonedx.Licenses{
|
||||
{
|
||||
License: nil,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
assert.Len(t, pkg.Licenses, 0)
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ func encodeLicenses(p pkg.Package) *cyclonedx.Licenses {
|
|||
func decodeLicenses(c *cyclonedx.Component) (out []string) {
|
||||
if c.Licenses != nil {
|
||||
for _, l := range *c.Licenses {
|
||||
out = append(out, l.License.ID)
|
||||
if l.License != nil {
|
||||
out = append(out, l.License.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue