This is an automated email from the ASF dual-hosted git repository.

apupier pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f89928713ba7e0eeaf07633d821d3b8158d05311
Author: smjain <[email protected]>
AuthorDate: Mon Oct 5 11:40:40 2026 +0530

    CAMEL-25305: camel-netty-http - an empty charset parameter is no charset
    
    A Content-Type with an empty charset parameter (text/plain; charset=) gave
    an empty charset name, which the consumer set as CamelCharsetName, so a 
later
    conversion failed in Charset.forName(""). Treat it as no charset, as the
    Undertow helper does, and re-wrap the upgrade guide entry.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../camel/component/netty/http/NettyHttpHelper.java       |  6 ++++--
 .../netty/http/NettyHttpStringBodyCharsetTest.java        | 15 +++++++++++++++
 .../modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc   |  5 +++--
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git 
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
 
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
index 9454acc599d4..f8e4e14dfe32 100644
--- 
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
+++ 
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
@@ -60,7 +60,8 @@ public final class NettyHttpHelper {
      * Gets the charset parameter of the content type. The parameter name is 
case-insensitive (RFC 9110, section 5.6.6).
      *
      * @param  contentType the content type, may be <tt>null</tt>
-     * @return             the charset name, or <tt>null</tt> if the content 
type has no charset parameter
+     * @return             the charset name, or <tt>null</tt> if the content 
type has no charset parameter, or an empty
+     *                     one
      */
     public static String getCharsetFromContentType(String contentType) {
         if (contentType == null) {
@@ -70,7 +71,8 @@ public final class NettyHttpHelper {
         for (int i = 1; i < parts.length; i++) {
             String part = parts[i].trim();
             if (part.regionMatches(true, 0, "charset=", 0, 8)) {
-                return IOHelper.normalizeCharset(part.substring(8));
+                String name = IOHelper.normalizeCharset(part.substring(8));
+                return ObjectHelper.isEmpty(name) ? null : name;
             }
         }
         return null;
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpStringBodyCharsetTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpStringBodyCharsetTest.java
index 727b17ab75c5..276abcb4ae85 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpStringBodyCharsetTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpStringBodyCharsetTest.java
@@ -86,6 +86,21 @@ public class NettyHttpStringBodyCharsetTest extends 
BaseNettyTestSupport {
         assertNull(NettyHttpHelper.getCharsetFromContentType("text/plain"));
         
assertNull(NettyHttpHelper.getCharsetFromContentType("multipart/form-data; 
boundary=charset"));
         assertNull(NettyHttpHelper.getCharsetFromContentType(null));
+        // an empty charset parameter is no charset
+        assertNull(NettyHttpHelper.getCharsetFromContentType("text/plain; 
charset="));
+        assertNull(NettyHttpHelper.getCharsetFromContentType("text/plain; 
charset=\"\""));
+    }
+
+    @Test
+    public void testRequestWithEmptyCharsetParameter() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:text");
+        mock.expectedBodiesReceived(TEXT);
+
+        // an empty charset is ignored: no CamelCharsetName is set, and the 
body is read as before
+        send("/text", "text/plain; charset=", 
TEXT.getBytes(StandardCharsets.UTF_8));
+
+        mock.assertIsSatisfied();
+        
assertNull(mock.getReceivedExchanges().get(0).getProperty(Exchange.CHARSET_NAME));
     }
 
     private HttpResponse<byte[]> send(String path, String contentType, byte[] 
body) throws Exception {
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
index 4746ecf2b297..df61b679b487 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
@@ -810,8 +810,9 @@ The Netty HTTP consumer (response) and producer (request) 
wrote a `String` body
 `text/plain; charset=ISO-8859-1` set by the route). A `String` body is now 
written in the charset that the
 `Content-Type` declares. Bodies that are not a `String`, and messages whose 
`Content-Type` declares no charset, are
 sent as before. Also, the `charset` parameter of a received `Content-Type` (a 
request on the consumer) is now
-recognized whatever its case (`Charset=ISO-8859-1`). A peer that ignored the 
declared charset and read such a message as UTF-8 must now use the
-declared charset, and characters that the declared charset cannot represent 
are written as `?`.
+recognized whatever its case (`Charset=ISO-8859-1`). A peer that ignored the 
declared charset and read such a
+message as UTF-8 must now use the declared charset, and characters that the 
declared charset cannot represent are
+written as `?`.
 
 === camel-snmp - GET_NEXT (walk)
 

Reply via email to