From 3435636ca0817783a44a26bab2225110e83c562d Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 3 Jan 2022 22:25:35 -0500 Subject: [PATCH 1/2] Replace use-experimental Kotlin compiler flags with opt-in --- app/build.gradle.kts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c7d59c1662..dc80b98034 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -292,12 +292,12 @@ tasks { kotlinOptions.freeCompilerArgs += listOf( "-Xopt-in=kotlin.Experimental", "-Xopt-in=kotlin.RequiresOptIn", - "-Xuse-experimental=kotlin.ExperimentalStdlibApi", - "-Xuse-experimental=kotlinx.coroutines.FlowPreview", - "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi", - "-Xuse-experimental=kotlinx.coroutines.InternalCoroutinesApi", - "-Xuse-experimental=kotlinx.serialization.ExperimentalSerializationApi", - "-Xuse-experimental=coil.annotation.ExperimentalCoilApi", + "-Xopt-in=kotlin.ExperimentalStdlibApi", + "-Xopt-in=kotlinx.coroutines.FlowPreview", + "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", + "-Xopt-in=kotlinx.coroutines.InternalCoroutinesApi", + "-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi", + "-Xopt-in=coil.annotation.ExperimentalCoilApi", ) } From d04d676d2f3808226e8e3b2d8c49b3d83004f7eb Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 5 Jan 2022 17:42:38 -0500 Subject: [PATCH 2/2] URL encode Kitsu search queries (fixes #5712) --- .../eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt | 3 ++- .../java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt | 4 +++- .../java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt index a2c1f22b29..b2a9abfd09 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt @@ -24,6 +24,7 @@ import okhttp3.OkHttpClient import okhttp3.Request import uy.kohesive.injekt.injectLazy import java.net.URLEncoder +import java.nio.charset.StandardCharsets class BangumiApi(private val client: OkHttpClient, interceptor: BangumiInterceptor) { @@ -70,7 +71,7 @@ class BangumiApi(private val client: OkHttpClient, interceptor: BangumiIntercept suspend fun search(search: String): List { return withIOContext { - val url = "$apiUrl/search/subject/${URLEncoder.encode(search, Charsets.UTF_8.name())}" + val url = "$apiUrl/search/subject/${URLEncoder.encode(search, StandardCharsets.UTF_8.name())}" .toUri() .buildUpon() .appendQueryParameter("max_results", "20") diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt index 4b6710239f..29e148461e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt @@ -24,6 +24,8 @@ import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody import okhttp3.RequestBody.Companion.toRequestBody +import java.net.URLEncoder +import java.nio.charset.StandardCharsets class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) { @@ -125,7 +127,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) private suspend fun algoliaSearch(key: String, query: String): List { return withIOContext { val jsonObject = buildJsonObject { - put("params", "query=$query$algoliaFilter") + put("params", "query=${URLEncoder.encode(query, StandardCharsets.UTF_8.name())}$algoliaFilter") } client.newCall( diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt index ab8c1c933b..d03cb92ca1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.util.lang import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator +import java.nio.charset.StandardCharsets import kotlin.math.floor /** @@ -41,7 +42,7 @@ fun String.compareToCaseInsensitiveNaturalOrder(other: String): Int { * Returns the size of the string as the number of bytes. */ fun String.byteSize(): Int { - return toByteArray(Charsets.UTF_8).size + return toByteArray(StandardCharsets.UTF_8).size } /** @@ -49,7 +50,7 @@ fun String.byteSize(): Int { * string is shorter. */ fun String.takeBytes(n: Int): String { - val bytes = toByteArray(Charsets.UTF_8) + val bytes = toByteArray(StandardCharsets.UTF_8) return if (bytes.size <= n) { this } else {