From f0eb6bd1ccced79ee04256e9aeb457f65bc7ea30 Mon Sep 17 00:00:00 2001 From: Jonathan Hedley Date: Fri, 20 Oct 2023 12:08:20 +1100 Subject: [PATCH] Don't recode ascii only strings --- src/main/java/org/jsoup/helper/HttpConnection.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jsoup/helper/HttpConnection.java b/src/main/java/org/jsoup/helper/HttpConnection.java index af7a18aa29..6bc52e1c7a 100644 --- a/src/main/java/org/jsoup/helper/HttpConnection.java +++ b/src/main/java/org/jsoup/helper/HttpConnection.java @@ -1145,11 +1145,13 @@ private static boolean looksLikeUtf8(byte[] input) { } int end; + boolean foundNonAscii = false; for (int j = input.length; i < j; ++i) { int o = input[i]; if ((o & 0x80) == 0) { continue; // ASCII } + foundNonAscii = true; // UTF-8 leading: if ((o & 0xE0) == 0xC0) { @@ -1173,7 +1175,7 @@ private static boolean looksLikeUtf8(byte[] input) { } } } - return true; + return foundNonAscii; } private @Nullable static String setOutputContentType(final Connection.Request req) {