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

Fixes #1179 Deprecated SPDX license #1263

Merged
merged 3 commits into from
Oct 14, 2022
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
72 changes: 36 additions & 36 deletions internal/spdxlicense/generate/generate_license_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ func TestReplaceDeprecatedLicenses(t *testing.T) {
}

expected := map[string]string{
"abc-1": "ABC-1.0-Only",
"abc-1-only": "ABC-1.0-Only",
"abc-1.0": "ABC-1.0-Only",
"abc-1.0.0": "ABC-1.0-Only",
"abc-1.0-only": "ABC-1.0-Only",
"abc-1.0.0-only": "ABC-1.0-Only",
"abc-1+": "ABC-1.0-Or-later",
"abc-1.0+": "ABC-1.0-Or-later",
"abc-1.0.0+": "ABC-1.0-Or-later",
"abc-1-or-later": "ABC-1.0-Or-later",
"abc-1.0-or-later": "ABC-1.0-Or-later",
"abc-1.0.0-or-later": "ABC-1.0-Or-later",
"abc-1": "ABC-1.0-only",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that the casing has changed here, but just wanted to confirm for others who come across this that these are correct as of 3.18:

https://spdx.org/licenses/ <-- "or" and "only" are lower cased here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe these should be lower cased. I don't see any license with upper case variants.

"abc-1-only": "ABC-1.0-only",
"abc-1.0": "ABC-1.0-only",
"abc-1.0.0": "ABC-1.0-only",
"abc-1.0-only": "ABC-1.0-only",
"abc-1.0.0-only": "ABC-1.0-only",
"abc-1+": "ABC-1.0-or-later",
"abc-1.0+": "ABC-1.0-or-later",
"abc-1.0.0+": "ABC-1.0-or-later",
"abc-1-or-later": "ABC-1.0-or-later",
"abc-1.0-or-later": "ABC-1.0-or-later",
"abc-1.0.0-or-later": "ABC-1.0-or-later",
"duh-1": "Duh-1.0",
"duh-1.0": "Duh-1.0",
"duh-1.0.0": "Duh-1.0",
Expand Down Expand Up @@ -79,22 +79,22 @@ func Test_processSPDXLicense(t *testing.T) {
"afl-3.0": "AFL-3.0",
"afl-3.0.0": "AFL-3.0",
"afmparse": "Afmparse",
"agpl-1": "AGPL-1.0",
"agpl-1": "AGPL-1.0-only",
"agpl-1-only": "AGPL-1.0-only",
"agpl-1-or-later": "AGPL-1.0-or-later",
"agpl-1.0": "AGPL-1.0",
"agpl-1.0": "AGPL-1.0-only",
"agpl-1.0-only": "AGPL-1.0-only",
"agpl-1.0-or-later": "AGPL-1.0-or-later",
"agpl-1.0.0": "AGPL-1.0",
"agpl-1.0.0": "AGPL-1.0-only",
"agpl-1.0.0-only": "AGPL-1.0-only",
"agpl-1.0.0-or-later": "AGPL-1.0-or-later",
"agpl-3": "AGPL-3.0",
"agpl-3": "AGPL-3.0-only",
"agpl-3-only": "AGPL-3.0-only",
"agpl-3-or-later": "AGPL-3.0-or-later",
"agpl-3.0": "AGPL-3.0",
"agpl-3.0": "AGPL-3.0-only",
"agpl-3.0-only": "AGPL-3.0-only",
"agpl-3.0-or-later": "AGPL-3.0-or-later",
"agpl-3.0.0": "AGPL-3.0",
"agpl-3.0.0": "AGPL-3.0-only",
"agpl-3.0.0-only": "AGPL-3.0-only",
"agpl-3.0.0-or-later": "AGPL-3.0-or-later",
"aladdin": "Aladdin",
Expand Down Expand Up @@ -160,18 +160,18 @@ func Test_processSPDXLicense(t *testing.T) {
"bsd-1.0-clause": "BSD-1-Clause",
"bsd-1.0.0-clause": "BSD-1-Clause",
"bsd-2-clause": "BSD-2-Clause",
"bsd-2-clause-freebsd": "BSD-2-Clause-FreeBSD",
"bsd-2-clause-netbsd": "BSD-2-Clause-NetBSD",
"bsd-2-clause-freebsd": "BSD-2-Clause-Views",
"bsd-2-clause-netbsd": "BSD-2-Clause",
"bsd-2-clause-patent": "BSD-2-Clause-Patent",
"bsd-2-clause-views": "BSD-2-Clause-Views",
"bsd-2.0-clause": "BSD-2-Clause",
"bsd-2.0-clause-freebsd": "BSD-2-Clause-FreeBSD",
"bsd-2.0-clause-netbsd": "BSD-2-Clause-NetBSD",
"bsd-2.0-clause-freebsd": "BSD-2-Clause-Views",
"bsd-2.0-clause-netbsd": "BSD-2-Clause",
"bsd-2.0-clause-patent": "BSD-2-Clause-Patent",
"bsd-2.0-clause-views": "BSD-2-Clause-Views",
"bsd-2.0.0-clause": "BSD-2-Clause",
"bsd-2.0.0-clause-freebsd": "BSD-2-Clause-FreeBSD",
"bsd-2.0.0-clause-netbsd": "BSD-2-Clause-NetBSD",
"bsd-2.0.0-clause-freebsd": "BSD-2-Clause-Views",
"bsd-2.0.0-clause-netbsd": "BSD-2-Clause",
"bsd-2.0.0-clause-patent": "BSD-2-Clause-Patent",
"bsd-2.0.0-clause-views": "BSD-2-Clause-Views",
"bsd-3-clause": "BSD-3-Clause",
Expand Down Expand Up @@ -221,9 +221,9 @@ func Test_processSPDXLicense(t *testing.T) {
"busl-1": "BUSL-1.1",
"busl-1.1": "BUSL-1.1",
"busl-1.1.0": "BUSL-1.1",
"bzip2-1": "bzip2-1.0.5",
"bzip2-1.0": "bzip2-1.0.5",
"bzip2-1.0.5": "bzip2-1.0.5",
"bzip2-1": "bzip2-1.0.6",
"bzip2-1.0": "bzip2-1.0.6",
"bzip2-1.0.5": "bzip2-1.0.6",
"bzip2-1.0.6": "bzip2-1.0.6",
"c-uda-1": "C-UDA-1.0",
"c-uda-1.0": "C-UDA-1.0",
Expand Down Expand Up @@ -520,49 +520,49 @@ func Test_processSPDXLicense(t *testing.T) {
"fsfullr": "FSFULLR",
"ftl": "FTL",
"gd": "GD",
"gfdl-1": "GFDL-1.1",
"gfdl-1": "GFDL-1.1-only",
"gfdl-1-invariants-only": "GFDL-1.1-invariants-only",
"gfdl-1-invariants-or-later": "GFDL-1.1-invariants-or-later",
"gfdl-1-no-invariants-only": "GFDL-1.1-no-invariants-only",
"gfdl-1-no-invariants-or-later": "GFDL-1.1-no-invariants-or-later",
"gfdl-1-only": "GFDL-1.1-only",
"gfdl-1-or-later": "GFDL-1.1-or-later",
"gfdl-1.1": "GFDL-1.1",
"gfdl-1.1": "GFDL-1.1-only",
"gfdl-1.1-invariants-only": "GFDL-1.1-invariants-only",
"gfdl-1.1-invariants-or-later": "GFDL-1.1-invariants-or-later",
"gfdl-1.1-no-invariants-only": "GFDL-1.1-no-invariants-only",
"gfdl-1.1-no-invariants-or-later": "GFDL-1.1-no-invariants-or-later",
"gfdl-1.1-only": "GFDL-1.1-only",
"gfdl-1.1-or-later": "GFDL-1.1-or-later",
"gfdl-1.1.0": "GFDL-1.1",
"gfdl-1.1.0": "GFDL-1.1-only",
"gfdl-1.1.0-invariants-only": "GFDL-1.1-invariants-only",
"gfdl-1.1.0-invariants-or-later": "GFDL-1.1-invariants-or-later",
"gfdl-1.1.0-no-invariants-only": "GFDL-1.1-no-invariants-only",
"gfdl-1.1.0-no-invariants-or-later": "GFDL-1.1-no-invariants-or-later",
"gfdl-1.1.0-only": "GFDL-1.1-only",
"gfdl-1.1.0-or-later": "GFDL-1.1-or-later",
"gfdl-1.2": "GFDL-1.2",
"gfdl-1.2": "GFDL-1.2-only",
"gfdl-1.2-invariants-only": "GFDL-1.2-invariants-only",
"gfdl-1.2-invariants-or-later": "GFDL-1.2-invariants-or-later",
"gfdl-1.2-no-invariants-only": "GFDL-1.2-no-invariants-only",
"gfdl-1.2-no-invariants-or-later": "GFDL-1.2-no-invariants-or-later",
"gfdl-1.2-only": "GFDL-1.2-only",
"gfdl-1.2-or-later": "GFDL-1.2-or-later",
"gfdl-1.2.0": "GFDL-1.2",
"gfdl-1.2.0": "GFDL-1.2-only",
"gfdl-1.2.0-invariants-only": "GFDL-1.2-invariants-only",
"gfdl-1.2.0-invariants-or-later": "GFDL-1.2-invariants-or-later",
"gfdl-1.2.0-no-invariants-only": "GFDL-1.2-no-invariants-only",
"gfdl-1.2.0-no-invariants-or-later": "GFDL-1.2-no-invariants-or-later",
"gfdl-1.2.0-only": "GFDL-1.2-only",
"gfdl-1.2.0-or-later": "GFDL-1.2-or-later",
"gfdl-1.3": "GFDL-1.3",
"gfdl-1.3": "GFDL-1.3-only",
"gfdl-1.3-invariants-only": "GFDL-1.3-invariants-only",
"gfdl-1.3-invariants-or-later": "GFDL-1.3-invariants-or-later",
"gfdl-1.3-no-invariants-only": "GFDL-1.3-no-invariants-only",
"gfdl-1.3-no-invariants-or-later": "GFDL-1.3-no-invariants-or-later",
"gfdl-1.3-only": "GFDL-1.3-only",
"gfdl-1.3-or-later": "GFDL-1.3-or-later",
"gfdl-1.3.0": "GFDL-1.3",
"gfdl-1.3.0": "GFDL-1.3-only",
"gfdl-1.3.0-invariants-only": "GFDL-1.3-invariants-only",
"gfdl-1.3.0-invariants-or-later": "GFDL-1.3-invariants-or-later",
"gfdl-1.3.0-no-invariants-only": "GFDL-1.3-no-invariants-only",
Expand Down Expand Up @@ -686,11 +686,11 @@ func Test_processSPDXLicense(t *testing.T) {
"lgpl-2.0.0-only": "LGPL-2.0-only",
"lgpl-2.0.0-or-later": "LGPL-2.0-or-later",
"lgpl-2.1": "LGPL-2.1-only",
"lgpl-2.1+": "LGPL-2.1+",
"lgpl-2.1+": "LGPL-2.1-or-later",
"lgpl-2.1-only": "LGPL-2.1-only",
"lgpl-2.1-or-later": "LGPL-2.1-or-later",
"lgpl-2.1.0": "LGPL-2.1-only",
"lgpl-2.1.0+": "LGPL-2.1+",
"lgpl-2.1.0+": "LGPL-2.1-or-later",
"lgpl-2.1.0-only": "LGPL-2.1-only",
"lgpl-2.1.0-or-later": "LGPL-2.1-or-later",
"lgpl-3": "LGPL-3.0-only",
Expand Down
19 changes: 18 additions & 1 deletion internal/spdxlicense/generate/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ func (l License) canReplace(other License) bool {
return false
}

// We want to replace deprecated licenses with non-deprecated counterparts
// For more information, see: https://github.com/spdx/license-list-XML/issues/1676
if other.Deprecated {
switch {
case strings.ReplaceAll(l.ID, "-only", "") == other.ID:
return true
case strings.ReplaceAll(l.ID, "-or-later", "+") == other.ID:
return true
case l.ID == "BSD-2-Clause" && other.ID == "BSD-2-Clause-NetBSD":
return true
case l.ID == "BSD-2-Clause-Views" && other.ID == "BSD-2-Clause-FreeBSD":
return true
case l.ID == "bzip2-1.0.6" && other.ID == "bzip2-1.0.5":
return true
}
}

if l.Name != other.Name {
return false
}
Expand All @@ -43,7 +60,7 @@ func (l License) canReplace(other License) bool {
}
}

return l.ID != other.ID
return l.ID == other.ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we have to flip this here? I admit it's a little hard to reason about this case since it's the last one checked with so many other chances of an early return

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the look @spiffcs -- this function is canReplace, I think we haven't seen this bug because the other negative test conditions failed first. Basically: this function is trying to find any license that could be replaced by another license by checking equality in almost all the other fields. However, when it gets to the end here, the condition previously here is "if the ID is NOT the same, we can consider it equal". Two comments about this: 1) this is not ever triggered based on the current document, and 2) I really don't think this is right -- if at the end of all the checks, the IDs are the same, it would return false... which means maybe we have different Text...

}

func (ll LicenseList) findReplacementLicense(deprecated License) *License {
Expand Down
8 changes: 5 additions & 3 deletions internal/spdxlicense/generate/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var (
}

license2 = License{
ID: "ABC-1.0-Or-later",
ID: "ABC-1.0-or-later",
Name: "The ABC License 1.0",
}

Expand All @@ -26,7 +26,7 @@ var (
}

license4 = License{
ID: "ABC-1.0-Only",
ID: "ABC-1.0-only",
Name: "The ABC License 1.0 Only",
}
license5 = License{
Expand All @@ -53,7 +53,9 @@ func TestLicense_canReplace(t *testing.T) {
}

for _, tt := range tests {
assert.Equal(t, tt.expected, tt.l1.canReplace(tt.l2))
t.Run(tt.l1.ID+" - "+tt.l2.ID, func(t *testing.T) {
assert.Equal(t, tt.expected, tt.l1.canReplace(tt.l2))
})
}
}

Expand Down
Loading