Skip to content

Commit

Permalink
fix: inconsistent matches sort ordering
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Luhring <dluhring@chainguard.dev>
  • Loading branch information
luhring committed Jun 14, 2024
1 parent 5e8b460 commit 6c10fc1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions grype/match/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ func (m ByElements) Less(i, j int) bool {
sort.Strings(fixVersions2)
fixStr1 := strings.Join(fixVersions1, ",")
fixStr2 := strings.Join(fixVersions2, ",")

if fixStr1 == fixStr2 {
loc1 := m[i].Package.Locations.ToSlice()
loc2 := m[j].Package.Locations.ToSlice()
var locStr1 string
for _, location := range loc1 {
locStr1 += location.String()
}
var locStr2 string
for _, location := range loc2 {
locStr2 += location.String()
}

return locStr1 < locStr2
}
return fixStr1 < fixStr2
}
return m[i].Package.Type < m[j].Package.Type
Expand Down

0 comments on commit 6c10fc1

Please sign in to comment.