Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(license): always trim leading and trailing spaces for licenses #8095

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading