summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.devcontainer/devcontainer.json2
-rw-r--r--okhttp/src/main/kotlin/okhttp3/internal/-UtilCommon.kt6
-rw-r--r--okhttp/src/main/kotlin/okhttp3/internal/-UtilJvm.kt10
-rw-r--r--okhttp/src/test/java/okhttp3/ResponseBodyJvmTest.kt10
-rw-r--r--okhttp/src/test/java/okhttp3/RouteFailureTest.kt3
5 files changed, 18 insertions, 13 deletions
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index e35665913..8ade6e48f 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -1,5 +1,5 @@
{
- "image": "mcr.microsoft.com/devcontainers/java:17-bookworm",
+ "image": "mcr.microsoft.com/devcontainers/java:21-bookworm",
"features": {
"ghcr.io/devcontainers/features/java:1": {
"version": "17"
diff --git a/okhttp/src/main/kotlin/okhttp3/internal/-UtilCommon.kt b/okhttp/src/main/kotlin/okhttp3/internal/-UtilCommon.kt
index 3db8d43a9..16d1321b5 100644
--- a/okhttp/src/main/kotlin/okhttp3/internal/-UtilCommon.kt
+++ b/okhttp/src/main/kotlin/okhttp3/internal/-UtilCommon.kt
@@ -55,12 +55,12 @@ internal val UNICODE_BOMS =
"efbbbf".decodeHex(),
// UTF-16BE.
"feff".decodeHex(),
+ // UTF-32LE.
+ "fffe0000".decodeHex(),
// UTF-16LE.
"fffe".decodeHex(),
// UTF-32BE.
- "0000ffff".decodeHex(),
- // UTF-32LE.
- "ffff0000".decodeHex(),
+ "0000feff".decodeHex(),
)
/**
diff --git a/okhttp/src/main/kotlin/okhttp3/internal/-UtilJvm.kt b/okhttp/src/main/kotlin/okhttp3/internal/-UtilJvm.kt
index 1f1c4f4e3..71014a703 100644
--- a/okhttp/src/main/kotlin/okhttp3/internal/-UtilJvm.kt
+++ b/okhttp/src/main/kotlin/okhttp3/internal/-UtilJvm.kt
@@ -94,14 +94,18 @@ internal fun format(
return String.format(Locale.US, format, *args)
}
+/**
+ * will also strip BOM from the source
+ */
@Throws(IOException::class)
internal fun BufferedSource.readBomAsCharset(default: Charset): Charset {
return when (select(UNICODE_BOMS)) {
+ // a mapping from the index of encoding methods in UNICODE_BOMS to its corresponding encoding method
0 -> UTF_8
1 -> UTF_16BE
- 2 -> UTF_16LE
- 3 -> UTF_32BE
- 4 -> UTF_32LE
+ 2 -> UTF_32LE
+ 3 -> UTF_16LE
+ 4 -> UTF_32BE
-1 -> default
else -> throw AssertionError()
}
diff --git a/okhttp/src/test/java/okhttp3/ResponseBodyJvmTest.kt b/okhttp/src/test/java/okhttp3/ResponseBodyJvmTest.kt
index a7967e92f..730a77bed 100644
--- a/okhttp/src/test/java/okhttp3/ResponseBodyJvmTest.kt
+++ b/okhttp/src/test/java/okhttp3/ResponseBodyJvmTest.kt
@@ -62,7 +62,7 @@ class ResponseBodyJvmTest {
@Test
fun stringBomOverridesExplicitCharset() {
- val body = body("0000ffff00000068000000650000006c0000006c0000006f", "utf-8")
+ val body = body("0000feff00000068000000650000006c0000006c0000006f", "utf-8")
assertThat(body.string()).isEqualTo("hello")
}
@@ -86,13 +86,13 @@ class ResponseBodyJvmTest {
@Test
fun stringBomUtf32Be() {
- val body = body("0000ffff00000068000000650000006c0000006c0000006f")
+ val body = body("0000feff00000068000000650000006c0000006c0000006f")
assertThat(body.string()).isEqualTo("hello")
}
@Test
fun stringBomUtf32Le() {
- val body = body("ffff000068000000650000006c0000006c0000006f000000")
+ val body = body("fffe000068000000650000006c0000006c0000006f000000")
assertThat(body.string()).isEqualTo("hello")
}
@@ -168,13 +168,13 @@ class ResponseBodyJvmTest {
@Test
fun readerBomUtf32Be() {
- val body = body("0000ffff00000068000000650000006c0000006c0000006f")
+ val body = body("0000feff00000068000000650000006c0000006c0000006f")
assertThat(exhaust(body.charStream())).isEqualTo("hello")
}
@Test
fun readerBomUtf32Le() {
- val body = body("ffff000068000000650000006c0000006c0000006f000000")
+ val body = body("fffe000068000000650000006c0000006c0000006f000000")
assertThat(exhaust(body.charStream())).isEqualTo("hello")
}
diff --git a/okhttp/src/test/java/okhttp3/RouteFailureTest.kt b/okhttp/src/test/java/okhttp3/RouteFailureTest.kt
index 4ced61578..c0884a454 100644
--- a/okhttp/src/test/java/okhttp3/RouteFailureTest.kt
+++ b/okhttp/src/test/java/okhttp3/RouteFailureTest.kt
@@ -316,7 +316,8 @@ class RouteFailureTest {
fun proxyMoveTest(cleanShutdown: Boolean) {
// Define a single Proxy at myproxy:8008 that will artificially move during the test
val proxySelector = RecordingProxySelector()
- proxySelector.proxies.add(Proxy(Proxy.Type.HTTP, InetSocketAddress("myproxy", 8008)))
+ val socketAddress = InetSocketAddress.createUnresolved("myproxy", 8008)
+ proxySelector.proxies.add(Proxy(Proxy.Type.HTTP, socketAddress))
// Define two host names for the DNS routing of fake proxy servers
val proxyServer1 = InetAddress.getByAddress("proxyServer1", byteArrayOf(127, 0, 0, 2))