From 1b31de4848a5c89252182bd9e948618e92c70ca8 Mon Sep 17 00:00:00 2001 From: Niels van Velzen Date: Wed, 30 Dec 2020 16:06:33 +0100 Subject: [PATCH] Fix uuid parser sometimes failing --- .../jellyfin/apiclient/model/serializer/UUIDSerializer.kt | 5 ++--- .../apiclient/model/serializer/UUIDSerializerTests.kt | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/jellyfin-model/src/main/kotlin/org/jellyfin/apiclient/model/serializer/UUIDSerializer.kt b/jellyfin-model/src/main/kotlin/org/jellyfin/apiclient/model/serializer/UUIDSerializer.kt index fed7fae9..d9d12f27 100644 --- a/jellyfin-model/src/main/kotlin/org/jellyfin/apiclient/model/serializer/UUIDSerializer.kt +++ b/jellyfin-model/src/main/kotlin/org/jellyfin/apiclient/model/serializer/UUIDSerializer.kt @@ -17,8 +17,7 @@ public class UUIDSerializer : KSerializer { override fun deserialize(decoder: Decoder): UUID { val uuid = decoder.decodeString() - return if (uuid.length == 32) UUID.fromString(uuid.replace(UUID_REGEX, "$1-$2-$3-$4-$5")) - else UUID.fromString(uuid) + return UUID.fromString(uuid.replace(UUID_REGEX, "$1-$2-$3-$4-$5")) } override fun serialize(encoder: Encoder, value: UUID) { @@ -26,6 +25,6 @@ public class UUIDSerializer : KSerializer { } private companion object { - private val UUID_REGEX = "^([a-z\\d]{8})([a-z\\d]{4})(4[a-z\\d]{3})([a-z\\d]{4})([a-z\\d]{12})\$".toRegex() + private val UUID_REGEX = "^([a-z\\d]{8})([a-z\\d]{4})([a-z\\d]{4})([a-z\\d]{4})([a-z\\d]{12})\$".toRegex() } } diff --git a/jellyfin-model/src/test/kotlin/org/jellyfin/apiclient/model/serializer/UUIDSerializerTests.kt b/jellyfin-model/src/test/kotlin/org/jellyfin/apiclient/model/serializer/UUIDSerializerTests.kt index 0bfe0148..fe0ca253 100644 --- a/jellyfin-model/src/test/kotlin/org/jellyfin/apiclient/model/serializer/UUIDSerializerTests.kt +++ b/jellyfin-model/src/test/kotlin/org/jellyfin/apiclient/model/serializer/UUIDSerializerTests.kt @@ -32,5 +32,13 @@ public class UUIDSerializerTests { UUID.fromString("713dc3fe-952b-438f-a70e-d35e4ef0525a"), Json.decodeFromString(instance, "\"713dc3fe952b438fa70ed35e4ef0525a\"") ) + assertEquals( + UUID.fromString("be275f0b-db14-71d8-6d2d-be5b8bb6918e"), + Json.decodeFromString(instance, "\"be275f0bdb1471d86d2dbe5b8bb6918e\"") + ) + assertEquals( + UUID.fromString("70a37b76-f996-24a5-7725-cbf8345e2b62"), + Json.decodeFromString(instance, "\"70a37b76f99624a57725cbf8345e2b62\"") + ) } }