mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-05 20:40:16 -08:00
fix(license): always trim leading and trailing spaces for licenses (#8095)
This commit is contained in:
@@ -641,7 +641,6 @@ var plusSuffixes = [3]string{"+", "-OR-LATER", " OR LATER"}
|
||||
func standardizeKeyAndSuffix(name string) expr.SimpleExpr {
|
||||
// Standardize space, including newline
|
||||
name = strings.Join(strings.Fields(name), " ")
|
||||
name = strings.TrimSpace(name)
|
||||
name = strings.ToUpper(name)
|
||||
// Do not perform any further normalization for URLs
|
||||
if strings.HasPrefix(name, "HTTP") {
|
||||
@@ -679,6 +678,8 @@ func Normalize(name string) string {
|
||||
}
|
||||
|
||||
func NormalizeLicense(name string) expr.SimpleExpr {
|
||||
// Always trim leading and trailing spaces, even if we don't find this license in `mapping`.
|
||||
name = strings.TrimSpace(name)
|
||||
normalized := standardizeKeyAndSuffix(name)
|
||||
if found, ok := mapping[normalized.License]; ok {
|
||||
return expr.SimpleExpr{License: found.License, HasPlus: found.HasPlus || normalized.HasPlus}
|
||||
|
||||
@@ -206,8 +206,8 @@ func TestNormalize(t *testing.T) {
|
||||
licenses: []string{
|
||||
" The unmapped license ",
|
||||
},
|
||||
normalized: " The unmapped license ",
|
||||
normalizedKey: " The unmapped license ",
|
||||
normalized: "The unmapped license",
|
||||
normalizedKey: "The unmapped license",
|
||||
},
|
||||
{
|
||||
licenses: []string{
|
||||
|
||||
Reference in New Issue
Block a user