Skip to content

Commit ecf4c60

Browse files
authored
fix: also compare PURL when sorting inventories (#1871)
#1865 Some inventories may have the same name and version but refer to different packages (e.g. Maven packages with the same artifact IDs). They may be considered as the same with the existing compare function and deduped during scanning. This PR adds PURL comparison so that these packages are not deduped unexpectedly.
1 parent 0e247a2 commit ecf4c60

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/scalibrextract/invsort.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ func inventorySort(a, b *extractor.Package) int {
1515
bLoc := fmt.Sprintf("%v", b.Locations)
1616

1717
var aExtr, bExtr string
18+
var aPURL, bPURL string
1819
if a.Extractor != nil {
1920
aExtr = a.Extractor.Name()
21+
if purl := a.Extractor.ToPURL(a); purl != nil {
22+
aPURL = purl.String()
23+
}
2024
}
2125
if b.Extractor != nil {
2226
bExtr = b.Extractor.Name()
27+
if purl := b.Extractor.ToPURL(b); purl != nil {
28+
bPURL = purl.String()
29+
}
2330
}
2431

2532
aSourceCode := fmt.Sprintf("%v", a.SourceCode)
@@ -31,5 +38,6 @@ func inventorySort(a, b *extractor.Package) int {
3138
cmp.Compare(a.Version, b.Version),
3239
cmp.Compare(aSourceCode, bSourceCode),
3340
cmp.Compare(aExtr, bExtr),
41+
cmp.Compare(aPURL, bPURL),
3442
)
3543
}

0 commit comments

Comments
 (0)