Skip to content

Commit f7c8d20

Browse files
authored
fix: fix version comparison between versions with different part count (#1838)
1 parent bb270d4 commit f7c8d20

File tree

2 files changed

+6
-0
lines changed
  • shared-internal/src
    • main/kotlin/io/github/typesafegithub/workflows/shared/internal/model
    • test/kotlin/io/github/typesafegithub/workflows/shared/internal/model

2 files changed

+6
-0
lines changed

shared-internal/src/main/kotlin/io/github/typesafegithub/workflows/shared/internal/model/Version.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ data class Version(
2525
return -1
2626
} else if (otherIntPart == null) {
2727
return 1
28+
} else {
29+
val comparison = intPart.compareTo(otherIntPart)
30+
if (comparison != 0) return comparison
2831
}
2932
}
3033
if (versionParts.size < other.versionParts.size) return -1

shared-internal/src/test/kotlin/io/github/typesafegithub/workflows/shared/internal/model/VersionTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class VersionTest :
5252
Triple("alpha", "beta", false),
5353
Triple("1.2.3", "1.2.3.4", false),
5454
Triple("3.2.1", "v3", true),
55+
Triple("v1.2.1", "v2", false),
56+
Triple("v1.2", "v2", false),
57+
Triple("v1.2.1", "v1.3", false),
5558
).forEach { (left, right, leftIsGreater) ->
5659
test("compareTo works correctly for $left vs. $right") {
5760
if (leftIsGreater) {

0 commit comments

Comments
 (0)