Skip to content

Commit

Permalink
fix(license): always trim leading and trailing spaces for licenses (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen authored Dec 13, 2024
1 parent f9fceb5 commit f5e4291
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/licensing/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions pkg/licensing/normalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit f5e4291

Please sign in to comment.