Skip to content

Commit b11bc50

Browse files
committed
fix(spdx-utils): Compare SPDX expressions case-insensitively
Fixes #3289. Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
1 parent 883a80a commit b11bc50

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,10 @@ class SpdxLicenseWithExceptionExpression(
524524

525525
override fun equals(other: Any?) =
526526
when (other) {
527-
is SpdxLicenseWithExceptionExpression -> license == other.license && exception == other.exception
527+
is SpdxLicenseWithExceptionExpression -> {
528+
license == other.license && exception.equals(other.exception, ignoreCase = true)
529+
}
530+
528531
else -> false
529532
}
530533

@@ -581,7 +584,10 @@ class SpdxLicenseIdExpression(
581584

582585
override fun equals(other: Any?) =
583586
when (other) {
584-
is SpdxLicenseIdExpression -> id == other.id && orLaterVersion == other.orLaterVersion
587+
is SpdxLicenseIdExpression -> {
588+
id.equals(other.id, ignoreCase = true) && orLaterVersion == other.orLaterVersion
589+
}
590+
585591
else -> false
586592
}
587593

@@ -622,7 +628,7 @@ data class SpdxLicenseReferenceExpression(
622628

623629
override fun equals(other: Any?) =
624630
when (other) {
625-
is SpdxLicenseReferenceExpression -> id == other.id
631+
is SpdxLicenseReferenceExpression -> id.equals(other.id, ignoreCase = true)
626632
else -> false
627633
}
628634

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@ class SpdxExpressionTest : WordSpec({
557557
"a".toSpdx() shouldNotBe "a AND b".toSpdx()
558558
"a".toSpdx() shouldNotBe "a+".toSpdx()
559559
}
560+
561+
"compare expressions case-insensitively" {
562+
"CDDL-1.1 OR GPL-2.0-only WITH Classpath-Exception-2.0".toSpdx() shouldBe
563+
"Cddl-1.1 OR Gpl-2.0-only WITH Classpath-exception-2.0".toSpdx()
564+
}
560565
}
561566

562567
"hashCode()" should {

0 commit comments

Comments
 (0)