Switched to UrlEncoder

This commit is contained in:
Erik C. Thauvin 2023-02-23 12:17:21 -08:00
parent 637503a0b2
commit bd3ee412fe
5 changed files with 24 additions and 33 deletions

2
.idea/kotlinc.xml generated
View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="KotlinJpsPluginSettings"> <component name="KotlinJpsPluginSettings">
<option name="version" value="1.8.0" /> <option name="version" value="1.8.10" />
</component> </component>
</project> </project>

View file

@ -1,10 +1,9 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { 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("io.gitlab.arturbosch.detekt") version "1.22.0"
id("java") id("java")
id("maven-publish") id("maven-publish")
@ -32,6 +31,7 @@ repositories {
dependencies { dependencies {
implementation(platform(kotlin("bom"))) implementation(platform(kotlin("bom")))
implementation("net.thauvin.erik:urlencoder:1.3.0")
implementation("org.json:json:20220924") implementation("org.json:json:20220924")
testImplementation(kotlin("test")) testImplementation(kotlin("test"))
@ -40,8 +40,9 @@ dependencies {
} }
java { java {
sourceCompatibility = JavaVersion.VERSION_11 toolchain {
targetCompatibility = JavaVersion.VERSION_11 languageVersion.set(JavaLanguageVersion.of(11))
}
withSourcesJar() withSourcesJar()
} }
@ -66,10 +67,6 @@ tasks {
useJUnitPlatform() useJUnitPlatform()
} }
withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = java.targetCompatibility.toString()
}
withType<Test> { withType<Test> {
testLogging { testLogging {
exceptionFormat = TestExceptionFormat.FULL exceptionFormat = TestExceptionFormat.FULL
@ -77,14 +74,6 @@ tasks {
} }
} }
withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
this.jvmTarget = java.targetCompatibility.toString()
}
withType<io.gitlab.arturbosch.detekt.DetektCreateBaselineTask>().configureEach {
this.jvmTarget = java.targetCompatibility.toString()
}
withType<GenerateMavenPom> { withType<GenerateMavenPom> {
destination = file("$projectDir/pom.xml") destination = file("$projectDir/pom.xml")
} }
@ -149,8 +138,8 @@ publishing {
} }
} }
scm { scm {
connection.set("scm:git://github.com/$gitHub.git") connection.set("scm:git:https://github.com/$gitHub.git")
developerConnection.set("scm:git@github.com:$gitHub.git") developerConnection.set("scm:git:git@github.com:$gitHub.git")
url.set(mavenUrl) url.set(mavenUrl)
} }
issueManagement { issueManagement {

14
pom.xml
View file

@ -27,8 +27,8 @@
</developer> </developer>
</developers> </developers>
<scm> <scm>
<connection>scm:git://github.com/ethauvin/jokeapi.git</connection> <connection>scm:git:https://github.com/ethauvin/jokeapi.git</connection>
<developerConnection>scm:git@github.com:ethauvin/jokeapi.git</developerConnection> <developerConnection>scm:git:git@github.com:ethauvin/jokeapi.git</developerConnection>
<url>https://github.com/ethauvin/jokeapi</url> <url>https://github.com/ethauvin/jokeapi</url>
</scm> </scm>
<issueManagement> <issueManagement>
@ -40,7 +40,7 @@
<dependency> <dependency>
<groupId>org.jetbrains.kotlin</groupId> <groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-bom</artifactId> <artifactId>kotlin-bom</artifactId>
<version>1.8.0</version> <version>1.8.10</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
@ -50,9 +50,15 @@
<dependency> <dependency>
<groupId>org.jetbrains.kotlin</groupId> <groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId> <artifactId>kotlin-stdlib-jdk8</artifactId>
<version>1.8.0</version> <version>1.8.10</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>net.thauvin.erik</groupId>
<artifactId>urlencoder</artifactId>
<version>1.3.0</version>
<scope>runtime</scope>
</dependency>
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>

View file

@ -41,9 +41,8 @@ import net.thauvin.erik.jokeapi.models.Joke
import net.thauvin.erik.jokeapi.models.Language import net.thauvin.erik.jokeapi.models.Language
import net.thauvin.erik.jokeapi.models.Parameter import net.thauvin.erik.jokeapi.models.Parameter
import net.thauvin.erik.jokeapi.models.Type import net.thauvin.erik.jokeapi.models.Type
import net.thauvin.erik.urlencoder.UrlEncoder
import org.json.JSONObject import org.json.JSONObject
import java.net.URLEncoder
import java.nio.charset.StandardCharsets
import java.util.logging.Logger import java.util.logging.Logger
import java.util.stream.Collectors import java.util.stream.Collectors
@ -86,10 +85,7 @@ object JokeApi {
val param = it.next() val param = it.next()
urlBuilder.append(param.key) urlBuilder.append(param.key)
if (param.value.isNotEmpty()) { if (param.value.isNotEmpty()) {
urlBuilder.append("=").append( urlBuilder.append("=").append(UrlEncoder.encode(param.value))
URLEncoder.encode(param.value, StandardCharsets.UTF_8).replace("+", "%20")
.replace("*", "%2A").replace("%7E", "~")
)
} }
if (it.hasNext()) { if (it.hasNext()) {
urlBuilder.append("&") urlBuilder.append("&")

View file

@ -74,8 +74,8 @@ class JokeConfig private constructor(
var idRange: IdRange = IdRange(), var idRange: IdRange = IdRange(),
var amount: Int = 1, var amount: Int = 1,
var safe: Boolean = false, var safe: Boolean = false,
var auth: String = "", var splitNewLine: Boolean = false,
var splitNewLine: Boolean = false var auth: String = ""
) { ) {
fun categories(categories: Set<Category>) = apply { this.categories = categories } fun categories(categories: Set<Category>) = apply { this.categories = categories }
fun lang(language: Language) = apply { lang = language } fun lang(language: Language) = apply { lang = language }
@ -86,8 +86,8 @@ class JokeConfig private constructor(
fun idRange(idRange: IdRange) = apply { this.idRange = idRange } fun idRange(idRange: IdRange) = apply { this.idRange = idRange }
fun amount(amount: Int) = apply { this.amount = amount } fun amount(amount: Int) = apply { this.amount = amount }
fun safe(safe: Boolean) = apply { this.safe = safe } 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 splitNewLine(splitNewLine: Boolean) = apply { this.splitNewLine = splitNewLine }
fun auth(auth: String) = apply { this.auth = auth }
fun build() = JokeConfig( fun build() = JokeConfig(
categories, lang, blacklistFlags, type, format, contains, idRange, amount, safe, splitNewLine, auth categories, lang, blacklistFlags, type, format, contains, idRange, amount, safe, splitNewLine, auth