mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 23:16:30 +01:00
fix: #953 Derive language from pURL - https://github.com/anchore/syft… (#957)
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
This commit is contained in:
@@ -86,6 +86,10 @@ func decodeComponent(c *cyclonedx.Component) *pkg.Package {
|
||||
p.Type = pkg.TypeFromPURL(p.PURL)
|
||||
}
|
||||
|
||||
if p.Language == "" {
|
||||
p.Language = pkg.LanguageFromPURL(p.PURL)
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
|
||||
@@ -191,3 +191,31 @@ func Test_deriveBomRef(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_decodeComponent(t *testing.T) {
|
||||
javaComponentWithNoSyftProperties := cyclonedx.Component{
|
||||
Name: "ch.qos.logback/logback-classic",
|
||||
Version: "1.2.3",
|
||||
PackageURL: "pkg:maven/ch.qos.logback/logback-classic@1.2.3",
|
||||
Type: "library",
|
||||
BOMRef: "pkg:maven/ch.qos.logback/logback-classic@1.2.3",
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
component cyclonedx.Component
|
||||
want pkg.Language
|
||||
}{
|
||||
{
|
||||
name: "derive language from pURL if missing",
|
||||
component: javaComponentWithNoSyftProperties,
|
||||
want: pkg.Java,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equal(t, tt.want, decodeComponent(&tt.component).Language)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user