mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-24 03:58:12 -08:00
fix(java): fix groupID selection by ArtifactID for jar files. (#3644)
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
@@ -142,6 +143,9 @@ func (d *DB) SearchByArtifactID(artifactID string) (string, error) {
|
||||
} else if len(indexes) == 0 {
|
||||
return "", xerrors.Errorf("artifactID %s: %w", artifactID, jar.ArtifactNotFoundErr)
|
||||
}
|
||||
sort.Slice(indexes, func(i, j int) bool {
|
||||
return indexes[i].GroupID < indexes[j].GroupID
|
||||
})
|
||||
|
||||
// Some artifacts might have the same artifactId.
|
||||
// e.g. "javax.servlet:jstl" and "jstl:jstl"
|
||||
@@ -157,6 +161,7 @@ func (d *DB) SearchByArtifactID(artifactID string) (string, error) {
|
||||
var groupID string
|
||||
for k, v := range groupIDs {
|
||||
if v > maxCount {
|
||||
maxCount = v
|
||||
groupID = k
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user