File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed
src/main/kotlin/com/featurevisor/sdk Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -210,23 +210,27 @@ object Conditions {
210210
211211 private fun normalizeSemver (version : String ): String {
212212 val parts = version.split(" -" , " +" )
213- val mainParts = parts[0 ].split(" ." ).map { it.toInt().toString() }
214- var normalizedVersion = mainParts.joinToString(" ." )
213+ val mainParts = parts[0 ].split(" ." )
215214
216- if (version.contains(" -" )) {
215+ val normalizedMainParts = mainParts.take(3 ).mapIndexed { _, part ->
216+ val num = part.toIntOrNull() ? : 0
217+ num.coerceAtMost(999 ).toString()
218+ }
219+
220+ var normalizedVersion = normalizedMainParts.joinToString(" ." )
221+
222+ if (parts.size > 1 && parts[1 ].isNotEmpty()) {
217223 val preRelease = parts[1 ].split(" ." ).joinToString(" ." ) {
218- if (it.all { char -> char.isDigit() }) it.toInt().toString()
219- else it
224+ it
220225 }
221226 normalizedVersion + = " -$preRelease "
222227 }
223228
224- if (version.contains( " + " )) {
225- val buildMetadata = version.split( " + " )[ 1 ]
229+ if (parts.size > 2 && parts[ 2 ].isNotEmpty( )) {
230+ val buildMetadata = parts[ 2 ]
226231 normalizedVersion + = " +$buildMetadata "
227232 }
228233
229234 return normalizedVersion
230235 }
231-
232236}
You can’t perform that action at this time.
0 commit comments