fix: normalize license OR parentheses #12
+8
-4
@@ -358,10 +358,7 @@ func pkgsiteLicenseExpression(licenses []pkgsiteLicense) string {
|
||||
types = append(types, typ)
|
||||
}
|
||||
sort.Strings(types)
|
||||
group := types[0]
|
||||
if len(types) > 1 {
|
||||
group = "(" + strings.Join(types, " OR ") + ")"
|
||||
}
|
||||
group := strings.Join(types, " OR ")
|
||||
seenGroups[group] = true
|
||||
}
|
||||
if len(seenGroups) == 0 {
|
||||
@@ -373,5 +370,12 @@ func pkgsiteLicenseExpression(licenses []pkgsiteLicense) string {
|
||||
groups = append(groups, group)
|
||||
}
|
||||
sort.Strings(groups)
|
||||
if len(groups) > 1 {
|
||||
for i, group := range groups {
|
||||
if strings.Contains(group, " OR ") {
|
||||
groups[i] = "(" + group + ")"
|
||||
}
|
||||
}
|
||||
}
|
||||
return strings.Join(groups, " AND ")
|
||||
}
|
||||
|
||||
+9
-1
@@ -48,7 +48,15 @@ func TestPkgsiteLicenseExpression(t *testing.T) {
|
||||
licenses: []pkgsiteLicense{
|
||||
{FilePath: "LICENSE", Types: []string{"MIT", "Apache-2.0"}},
|
||||
},
|
||||
want: "(Apache-2.0 OR MIT)",
|
||||
want: "Apache-2.0 OR MIT",
|
||||
},
|
||||
{
|
||||
name: "parenthesizes OR group when joined with AND",
|
||||
licenses: []pkgsiteLicense{
|
||||
{FilePath: "LICENSE", Types: []string{"MIT", "Apache-2.0"}},
|
||||
{FilePath: "COPYING", Types: []string{"BSD-3-Clause"}},
|
||||
},
|
||||
want: "(Apache-2.0 OR MIT) AND BSD-3-Clause",
|
||||
},
|
||||
{
|
||||
name: "uses TODO when pkgsite has no SPDX type",
|
||||
|
||||
Reference in New Issue
Block a user