Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for licenses not found on list
Browse files Browse the repository at this point in the history
Signed-off-by: Avi Deitcher <avi@deitcher.net>
deitch committed Feb 5, 2023

Verified

This commit was signed with the committer’s verified signature.
renovate-bot Mend Renovate
1 parent 9995950 commit 3c38d10
Showing 2 changed files with 30 additions and 3 deletions.
11 changes: 9 additions & 2 deletions internal/spdxlicense/license.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,13 @@ import (
//go:generate go run ./generate

func ID(id string) (string, bool) {
value, exists := licenseIDs[strings.ToLower(id)]
return value, exists
if strings.TrimSpace(id) == "" {
return "", false
}
// first look for a canonical license
if value, exists := licenseIDs[strings.ToLower(id)]; exists {
return value, exists
}
// we did not find, so treat it as a separate license
return "LicenseRef-" + id, true
}
22 changes: 21 additions & 1 deletion internal/spdxlicense/license_test.go
Original file line number Diff line number Diff line change
@@ -10,50 +10,70 @@ func TestIDParse(t *testing.T) {
var tests = []struct {
shortName string
spdx string
found bool
}{
{
"GPL-1-only",
"GPL-1.0-only",
true,
},
{
"GPL-2",
"GPL-2.0-only",
true,
},
{
"GPL-2+",
"GPL-2.0-or-later",
true,
},
{
"GPL-3.0.0-or-later",
"GPL-3.0-or-later",
true,
},
{
"GPL-3-with-autoconf-exception",
"GPL-3.0-with-autoconf-exception",
true,
},
{
"CC-by-nc-3-de",
"CC-BY-NC-3.0-DE",
true,
},
// the below few cases are NOT expected, however, seem unavoidable given the current approach
{
"w3c-20150513.0.0",
"W3C-20150513",
true,
},
{
"spencer-86.0.0",
"Spencer-86",
true,
},
{
"unicode-dfs-2015.0.0",
"Unicode-DFS-2015",
true,
},
{
"Unknown",
"LicenseRef-Unknown",
true,
},
{
" ",
"",
false,
},
}

for _, test := range tests {
t.Run(test.shortName, func(t *testing.T) {
got, exists := ID(test.shortName)
assert.True(t, exists)
assert.Equal(t, test.found, exists)
assert.Equal(t, test.spdx, got)
})
}

0 comments on commit 3c38d10

Please sign in to comment.