Skip to content

Commit a76e328

Browse files
authored
fix(sbom): take pkg name from purl for maven pkgs (#7008)
1 parent eb636c1 commit a76e328

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pkg/sbom/io/decode.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,14 @@ func (m *Decoder) pkgName(pkg *ftypes.Package, c *core.Component) string {
256256
return pkg.Name
257257
}
258258

259+
// `maven purl type` has no restrictions on using lowercase letters.
260+
// Also, `spdx-maven-plugin` uses `name` instead of `artifactId` for the `package name` field.
261+
// So we need to use `purl` for maven/gradle packages
262+
// See https://github.com/aquasecurity/trivy/issues/7007 for more information.
263+
if p.Type == packageurl.TypeMaven || p.Type == packageurl.TypeGradle {
264+
return pkg.Name
265+
}
266+
259267
// TODO(backward compatibility): Remove after 03/2025
260268
// Bitnami used different pkg.Name and the name from PURL.
261269
// For backwards compatibility - we need to use PURL.
@@ -265,9 +273,6 @@ func (m *Decoder) pkgName(pkg *ftypes.Package, c *core.Component) string {
265273
}
266274

267275
if c.Group != "" {
268-
if p.Type == packageurl.TypeMaven || p.Type == packageurl.TypeGradle {
269-
return c.Group + ":" + c.Name
270-
}
271276
return c.Group + "/" + c.Name
272277
}
273278
return c.Name

0 commit comments

Comments
 (0)