Skip to content

Commit f5e4291

Browse files
authored
fix(license): always trim leading and trailing spaces for licenses (#8095)
1 parent f9fceb5 commit f5e4291

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

pkg/licensing/normalize.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ var plusSuffixes = [3]string{"+", "-OR-LATER", " OR LATER"}
641641
func standardizeKeyAndSuffix(name string) expr.SimpleExpr {
642642
// Standardize space, including newline
643643
name = strings.Join(strings.Fields(name), " ")
644-
name = strings.TrimSpace(name)
645644
name = strings.ToUpper(name)
646645
// Do not perform any further normalization for URLs
647646
if strings.HasPrefix(name, "HTTP") {
@@ -679,6 +678,8 @@ func Normalize(name string) string {
679678
}
680679

681680
func NormalizeLicense(name string) expr.SimpleExpr {
681+
// Always trim leading and trailing spaces, even if we don't find this license in `mapping`.
682+
name = strings.TrimSpace(name)
682683
normalized := standardizeKeyAndSuffix(name)
683684
if found, ok := mapping[normalized.License]; ok {
684685
return expr.SimpleExpr{License: found.License, HasPlus: found.HasPlus || normalized.HasPlus}

pkg/licensing/normalize_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ func TestNormalize(t *testing.T) {
206206
licenses: []string{
207207
" The unmapped license ",
208208
},
209-
normalized: " The unmapped license ",
210-
normalizedKey: " The unmapped license ",
209+
normalized: "The unmapped license",
210+
normalizedKey: "The unmapped license",
211211
},
212212
{
213213
licenses: []string{

0 commit comments

Comments
 (0)