11package licensing
22
33import (
4- "slices"
5-
64 dbTypes "github.com/aquasecurity/trivy-db/pkg/types"
75 "github.com/aquasecurity/trivy/pkg/fanal/types"
86 "github.com/aquasecurity/trivy/pkg/licensing/expression"
7+ "github.com/aquasecurity/trivy/pkg/set"
98)
109
1110type ScannerOption struct {
@@ -22,17 +21,14 @@ func NewScanner(categories map[types.LicenseCategory][]string) Scanner {
2221}
2322
2423func (s * Scanner ) Scan (licenseName string ) (types.LicenseCategory , string ) {
25- normalized := NormalizeLicense (expression.SimpleExpr {License : licenseName })
26- var normalizedName string
27- switch normalized := normalized .(type ) {
28- case expression.SimpleExpr :
29- normalizedName = normalized .License
30- case expression.CompoundExpr :
31- normalizedName = normalized .String ()
24+ expr := NormalizeLicense (expression.SimpleExpr {License : licenseName })
25+ normalizedNames := set .New (expr .String ()) // The license name with suffix (e.g. AGPL-1.0-or-later)
26+ if se , ok := expr .(expression.SimpleExpr ); ok {
27+ normalizedNames .Append (se .License ) // Also accept the license name without suffix (e.g. AGPL-1.0)
3228 }
3329
3430 for category , names := range s .categories {
35- if slices . Contains ( names , normalizedName ) {
31+ if normalizedNames . Intersection ( set . New ( names ... )). Size () > 0 {
3632 return category , categoryToSeverity (category ).String ()
3733 }
3834 }
0 commit comments