From bd3ee412fe57b420a9c41c72bb02ef8e5de2d2b1 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 23 Feb 2023 12:17:21 -0800 Subject: [PATCH] Switched to UrlEncoder --- .idea/kotlinc.xml | 2 +- build.gradle.kts | 27 ++++++------------- pom.xml | 14 +++++++--- .../net/thauvin/erik/jokeapi/JokeApi.kt | 8 ++---- .../net/thauvin/erik/jokeapi/JokeConfig.kt | 6 ++--- 5 files changed, 24 insertions(+), 33 deletions(-) diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index 2b8a50f..0fc3113 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 604ff10..b8b1849 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,9 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent import org.jetbrains.dokka.gradle.DokkaTask -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - id("com.github.ben-manes.versions") version "0.45.0" + id("com.github.ben-manes.versions") version "0.46.0" id("io.gitlab.arturbosch.detekt") version "1.22.0" id("java") id("maven-publish") @@ -31,7 +30,8 @@ repositories { dependencies { implementation(platform(kotlin("bom"))) - + + implementation("net.thauvin.erik:urlencoder:1.3.0") implementation("org.json:json:20220924") testImplementation(kotlin("test")) @@ -40,8 +40,9 @@ dependencies { } java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + toolchain { + languageVersion.set(JavaLanguageVersion.of(11)) + } withSourcesJar() } @@ -66,10 +67,6 @@ tasks { useJUnitPlatform() } - withType().configureEach { - kotlinOptions.jvmTarget = java.targetCompatibility.toString() - } - withType { testLogging { exceptionFormat = TestExceptionFormat.FULL @@ -77,14 +74,6 @@ tasks { } } - withType().configureEach { - this.jvmTarget = java.targetCompatibility.toString() - } - - withType().configureEach { - this.jvmTarget = java.targetCompatibility.toString() - } - withType { destination = file("$projectDir/pom.xml") } @@ -149,8 +138,8 @@ publishing { } } scm { - connection.set("scm:git://github.com/$gitHub.git") - developerConnection.set("scm:git@github.com:$gitHub.git") + connection.set("scm:git:https://github.com/$gitHub.git") + developerConnection.set("scm:git:git@github.com:$gitHub.git") url.set(mavenUrl) } issueManagement { diff --git a/pom.xml b/pom.xml index d314f31..d809b72 100644 --- a/pom.xml +++ b/pom.xml @@ -27,8 +27,8 @@ - scm:git://github.com/ethauvin/jokeapi.git - scm:git@github.com:ethauvin/jokeapi.git + scm:git:https://github.com/ethauvin/jokeapi.git + scm:git:git@github.com:ethauvin/jokeapi.git https://github.com/ethauvin/jokeapi @@ -40,7 +40,7 @@ org.jetbrains.kotlin kotlin-bom - 1.8.0 + 1.8.10 pom import @@ -50,9 +50,15 @@ org.jetbrains.kotlin kotlin-stdlib-jdk8 - 1.8.0 + 1.8.10 compile + + net.thauvin.erik + urlencoder + 1.3.0 + runtime + org.json json diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeApi.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeApi.kt index 22f20a1..05b1bb1 100644 --- a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeApi.kt +++ b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeApi.kt @@ -41,9 +41,8 @@ import net.thauvin.erik.jokeapi.models.Joke import net.thauvin.erik.jokeapi.models.Language import net.thauvin.erik.jokeapi.models.Parameter import net.thauvin.erik.jokeapi.models.Type +import net.thauvin.erik.urlencoder.UrlEncoder import org.json.JSONObject -import java.net.URLEncoder -import java.nio.charset.StandardCharsets import java.util.logging.Logger import java.util.stream.Collectors @@ -86,10 +85,7 @@ object JokeApi { val param = it.next() urlBuilder.append(param.key) if (param.value.isNotEmpty()) { - urlBuilder.append("=").append( - URLEncoder.encode(param.value, StandardCharsets.UTF_8).replace("+", "%20") - .replace("*", "%2A").replace("%7E", "~") - ) + urlBuilder.append("=").append(UrlEncoder.encode(param.value)) } if (it.hasNext()) { urlBuilder.append("&") diff --git a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeConfig.kt b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeConfig.kt index 8378e23..544383c 100644 --- a/src/main/kotlin/net/thauvin/erik/jokeapi/JokeConfig.kt +++ b/src/main/kotlin/net/thauvin/erik/jokeapi/JokeConfig.kt @@ -74,8 +74,8 @@ class JokeConfig private constructor( var idRange: IdRange = IdRange(), var amount: Int = 1, var safe: Boolean = false, - var auth: String = "", - var splitNewLine: Boolean = false + var splitNewLine: Boolean = false, + var auth: String = "" ) { fun categories(categories: Set) = apply { this.categories = categories } fun lang(language: Language) = apply { lang = language } @@ -86,8 +86,8 @@ class JokeConfig private constructor( fun idRange(idRange: IdRange) = apply { this.idRange = idRange } fun amount(amount: Int) = apply { this.amount = amount } fun safe(safe: Boolean) = apply { this.safe = safe } - fun auth(auth: String) = apply { this.auth = auth } fun splitNewLine(splitNewLine: Boolean) = apply { this.splitNewLine = splitNewLine } + fun auth(auth: String) = apply { this.auth = auth } fun build() = JokeConfig( categories, lang, blacklistFlags, type, format, contains, idRange, amount, safe, splitNewLine, auth