From f5e429179df1637de96962ab9c19e4336056bb5d Mon Sep 17 00:00:00 2001 From: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:00:01 +0600 Subject: [PATCH] fix(license): always trim leading and trailing spaces for licenses (#8095) --- pkg/licensing/normalize.go | 3 ++- pkg/licensing/normalize_test.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/licensing/normalize.go b/pkg/licensing/normalize.go index bce81e68903d..2aba2df39167 100644 --- a/pkg/licensing/normalize.go +++ b/pkg/licensing/normalize.go @@ -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} diff --git a/pkg/licensing/normalize_test.go b/pkg/licensing/normalize_test.go index 7daf7b57d783..1895ca4ed75c 100644 --- a/pkg/licensing/normalize_test.go +++ b/pkg/licensing/normalize_test.go @@ -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{