Skip to content

Commit

Permalink
test(common-utils): Extend the percentEncode test with decoding
Browse files Browse the repository at this point in the history
Verify that Java's regular `URLDecoder` can decode string to the
original.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed May 24, 2024
1 parent 69f8c6e commit 53752d5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions utils/common/src/test/kotlin/ExtensionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import io.kotest.matchers.types.beInstanceOf
import java.io.File
import java.io.IOException
import java.net.URI
import java.net.URLDecoder
import java.time.DayOfWeek
import java.util.Locale

Expand Down Expand Up @@ -375,13 +376,21 @@ class ExtensionsTest : WordSpec({

assertSoftly {
reserved.forEach {
val hexString = String.format(Locale.ROOT, "%%%02X", it.code)
it.toString().percentEncode() shouldBe hexString
val decoded = it.toString()

val encoded = decoded.percentEncode()

encoded shouldBe String.format(Locale.ROOT, "%%%02X", it.code)
URLDecoder.decode(encoded, Charsets.UTF_8) shouldBe decoded
}

unreserved.forEach {
val singleCharString = it.toString()
singleCharString.percentEncode() shouldBe singleCharString
val decoded = it.toString()

val encoded = decoded.percentEncode()

encoded shouldBe decoded
URLDecoder.decode(encoded, Charsets.UTF_8) shouldBe decoded
}

" ".percentEncode() shouldBe "%20"
Expand Down

0 comments on commit 53752d5

Please sign in to comment.