Skip to content

Commit 8b19f27

Browse files
committed
spdx-utils: Ignore the '+' operator for SPDX license texts
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 <martin.nonnenmacher@bosch.io>
1 parent 5b6b493 commit 8b19f27

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

utils/spdx/src/main/kotlin/Utils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fun getLicenseTextReader(
150150
getLicenseTextFile(id, it)?.let { file -> { file.readText() } }
151151
}
152152
} else {
153-
SpdxLicense.forId(id)?.let { { it.text } }
153+
SpdxLicense.forId(id.removeSuffix("+"))?.let { { it.text } }
154154
?: SpdxLicenseException.forId(id)?.takeIf { handleExceptions }?.let { { it.text } }
155155
}
156156
}

utils/spdx/src/test/kotlin/UtilsTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ class UtilsTest : WordSpec() {
142142
text should endWith("limitations under the License.")
143143
}
144144

145+
"return the full license text for a valid SPDX license id with the '+' operator" {
146+
val text = getLicenseText("Apache-2.0+")?.trim()
147+
148+
text should startWith("Apache License")
149+
text should endWith("limitations under the License.")
150+
}
151+
145152
"return null for an invalid SPDX license id" {
146153
getLicenseText("FooBar-1.0") should beNull()
147154
}

0 commit comments

Comments
 (0)