Skip to content

Commit

Permalink
spdx-utils: Ignore the '+' operator for SPDX license texts
Browse files Browse the repository at this point in the history
Ignore the '+' operator when getting the license text of an SPDX
license. For example, for the id 'Apache-2.0+' return the license text
for 'Apache-2.0'. This is valid, because in the example 'Apache-2.0' is
a valid license for the expression.

Choosing a later version of the license should be implemented as an
extension of the license choice feature.

Fixes #5004.

Signed-off-by: Martin Nonnenmacher <[email protected]>
  • Loading branch information
mnonnenmacher committed Feb 10, 2022
1 parent 5b6b493 commit e82ae55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion utils/spdx/src/main/kotlin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fun getLicenseTextReader(
getLicenseTextFile(id, it)?.let { file -> { file.readText() } }
}
} else {
SpdxLicense.forId(id)?.let { { it.text } }
SpdxLicense.forId(id.removeSuffix("+"))?.let { { it.text } }
?: SpdxLicenseException.forId(id)?.takeIf { handleExceptions }?.let { { it.text } }
}
}
Expand Down
7 changes: 7 additions & 0 deletions utils/spdx/src/test/kotlin/UtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ class UtilsTest : WordSpec() {
text should endWith("limitations under the License.")
}

"return the full license text for a valid SPDX license id with the '+' operator" {
val text = getLicenseText("Apache-2.0+")?.trim()

text should startWith("Apache License")
text should endWith("limitations under the License.")
}

"return null for an invalid SPDX license id" {
getLicenseText("FooBar-1.0") should beNull()
}
Expand Down

0 comments on commit e82ae55

Please sign in to comment.