Skip to content

Commit

Permalink
semver version with more than 3 digits throws exception fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tan108 committed Dec 19, 2024
1 parent 9630444 commit 64652fd
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/main/kotlin/com/featurevisor/sdk/Conditions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,27 @@ object Conditions {

private fun normalizeSemver(version: String): String {
val parts = version.split("-", "+")
val mainParts = parts[0].split(".").map { it.toInt().toString() }
var normalizedVersion = mainParts.joinToString(".")
val mainParts = parts[0].split(".")

if (version.contains("-")) {
val normalizedMainParts = mainParts.take(3).mapIndexed { _, part ->
val num = part.toIntOrNull() ?: 0
num.coerceAtMost(999).toString()
}

var normalizedVersion = normalizedMainParts.joinToString(".")

if (parts.size > 1 && parts[1].isNotEmpty()) {
val preRelease = parts[1].split(".").joinToString(".") {
if (it.all { char -> char.isDigit() }) it.toInt().toString()
else it
it
}
normalizedVersion += "-$preRelease"
}

if (version.contains("+")) {
val buildMetadata = version.split("+")[1]
if (parts.size > 2 && parts[2].isNotEmpty()) {
val buildMetadata = parts[2]
normalizedVersion += "+$buildMetadata"
}

return normalizedVersion
}

}

0 comments on commit 64652fd

Please sign in to comment.