From 72fd4cc56499060dd099b197d1a3550dd057624a Mon Sep 17 00:00:00 2001 From: h-hyuuga <83582211+h-hyuuga@users.noreply.github.com> Date: Mon, 28 Jun 2021 05:50:09 -0400 Subject: [PATCH] Comick.fun: Fix parsing issue for nullable chapter numbers (#7902) --- src/all/comickfun/build.gradle | 2 +- .../all/comickfun/ComickFunSerialization.kt | 32 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/all/comickfun/build.gradle b/src/all/comickfun/build.gradle index 732961934..0a9efa021 100644 --- a/src/all/comickfun/build.gradle +++ b/src/all/comickfun/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'Comick.fun' pkgNameSuffix = 'all.comickfun' extClass = '.ComickFunFactory' - extVersionCode = 4 + extVersionCode = 5 libVersion = '1.2' containsNsfw = true } diff --git a/src/all/comickfun/src/eu/kanade/tachiyomi/extension/all/comickfun/ComickFunSerialization.kt b/src/all/comickfun/src/eu/kanade/tachiyomi/extension/all/comickfun/ComickFunSerialization.kt index 3d4c9f82e..8828afa0b 100644 --- a/src/all/comickfun/src/eu/kanade/tachiyomi/extension/all/comickfun/ComickFunSerialization.kt +++ b/src/all/comickfun/src/eu/kanade/tachiyomi/extension/all/comickfun/ComickFunSerialization.kt @@ -46,25 +46,23 @@ inline fun deepSelectDeserializer(vararg keys: String, tDeseri buildClassSerialDescriptor("$x\$${it.serialName}") { element(x, it) } } }.asReversed() - var a: ((Int) -> KSerializer)? = null - val b = { depth: Int -> - object : KSerializer { - override val descriptor = descriptors[depth] - override fun deserialize(decoder: Decoder): T { - return if (depth == keys.size) decoder.decodeSerializableValue(tDeserializer) - else decoder.decodeStructureByKnownName(descriptor) { names -> - names.filter { (name, _) -> name == keys[depth] } - .map { (_, index) -> decodeSerializableElement(descriptor, index, a!!(depth + 1)) } - .single() - } + return object : KSerializer { + private var depth = 0 + private fun asChild(fn: (KSerializer) -> S) = fn(this.apply { depth += 1 }).also { depth -= 1 } + override val descriptor get() = descriptors[depth] + + override fun deserialize(decoder: Decoder): T { + return if (depth == keys.size) decoder.decodeSerializableValue(tDeserializer) + else decoder.decodeStructureByKnownName(descriptor) { names -> + names.filter { (name, _) -> name == keys[depth] } + .map { (_, index) -> asChild { decodeSerializableElement(descriptors[depth - 1]/* find something more elegant */, index, it) } } + .single() } - - override fun serialize(encoder: Encoder, value: T) = throw UnsupportedOperationException("Not supported") } + + override fun serialize(encoder: Encoder, value: T) = throw UnsupportedOperationException("Not supported") } - a = b // this is the hackiest of hacky hacks to get around not being able to define recursive inline functions - return a(0) } /** @@ -157,8 +155,8 @@ class SChapterDeserializer : KSerializer { "title" -> title = decodeNullableSerializableElement(descriptor, index, serializer()) "vol" -> vol = decodeNullableSerializableElement(descriptor, index, serializer()) "chap" -> { - chap = decodeStringElement(descriptor, index) - chapter_number = chap!!.toFloat() + chap = decodeNullableSerializableElement(descriptor, index, serializer()) + chapter_number = chap?.toFloat() ?: -1f } "hid" -> hid = decodeStringElement(descriptor, index) "iso639_1" -> iso639_1 = decodeStringElement(descriptor, index)