mirror of
https://github.com/apple/pkl.git
synced 2026-05-28 17:49:15 +02:00
Use Locale.ROOT when lowercasing rewrite URIs (#1618)
Use Locale.ROOT to apply the lowecase format. For URI scheme and host locale-neutral casing is the semantically the correct choice. Added a unit test that sets the default locale to tr-TR and that would fail without the fix.
This commit is contained in:
@@ -26,6 +26,7 @@ import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
@@ -205,9 +206,9 @@ final class RequestRewritingClient implements HttpClient {
|
||||
private URI normalizeRewrite(URI uri) {
|
||||
try {
|
||||
return new URI(
|
||||
uri.getScheme().toLowerCase(),
|
||||
uri.getScheme().toLowerCase(Locale.ROOT),
|
||||
uri.getUserInfo(),
|
||||
uri.getHost().toLowerCase(),
|
||||
uri.getHost().toLowerCase(Locale.ROOT),
|
||||
uri.getPort(),
|
||||
uri.getPath(),
|
||||
uri.getQuery(),
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.net.http.HttpRequest
|
||||
import java.net.http.HttpRequest.BodyPublishers
|
||||
import java.net.http.HttpResponse.BodyHandlers
|
||||
import java.time.Duration
|
||||
import java.util.Locale
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatList
|
||||
import org.junit.jupiter.api.Test
|
||||
@@ -321,6 +322,24 @@ class RequestRewritingClientTest {
|
||||
.isEqualTo("https://bar.com/bar/baz")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rewrites URIs - host with capital I under tr_TR locale`() {
|
||||
// Under tr_TR, "INDEX.COM".toLowerCase() becomes "ındex.com".
|
||||
val previous = Locale.getDefault()
|
||||
Locale.setDefault(Locale.forLanguageTag("tr-TR"))
|
||||
try {
|
||||
assertThat(
|
||||
rewrittenRequest(
|
||||
"https://INDEX.COM/foo/bar",
|
||||
mapOf(URI("https://index.com/") to URI("https://bar.com/")),
|
||||
)
|
||||
)
|
||||
.isEqualTo("https://bar.com/foo/bar")
|
||||
} finally {
|
||||
Locale.setDefault(previous)
|
||||
}
|
||||
}
|
||||
|
||||
private fun rewrittenRequest(uri: String, rules: Map<URI, URI>): String {
|
||||
val captured = RequestCapturingClient()
|
||||
val client = RequestRewritingClient("Pkl", Duration.ofSeconds(42), -1, captured, rules, mapOf())
|
||||
|
||||
Reference in New Issue
Block a user