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

This commit is contained in:
DmitriyLewen
2024-12-13 14:00:01 +06:00
committed by GitHub
parent f9fceb58bf
commit f5e429179d
2 changed files with 4 additions and 3 deletions

View File

@@ -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}

View File

@@ -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{