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

bitstorm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/master by this push:
     new af0ca10eea Fall back to the default charset when its name is not a 
legal name (#1675)
af0ca10eea is described below

commit af0ca10eea4eddeac2372b30f7e6e26134dbc129
Author: VAMSI KRISHNA <[email protected]>
AuthorDate: Mon Oct 19 20:10:16 2026 +0530

    Fall back to the default charset when its name is not a legal name (#1675)
    
    Charset.forName throws IllegalCharsetNameException for a name that is
    not even a legal charset name, next to UnsupportedCharsetException for
    a legal but unknown one, and only the latter was caught. The name
    comes from the character encoding of the servlet request, which a
    client influences with the charset parameter of the Content-Type
    header, so a request could make Wicket fail with an unhandled runtime
    exception while it resolves the charset to decode the request.
    
    Both exceptions are now treated the same: the encoding is unknown and
    the default charset is used.
    
    Co-authored-by: 17krishna8 <[email protected]>
---
 .../test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java  | 3 +++
 .../src/main/java/org/apache/wicket/protocol/http/RequestUtils.java  | 5 +++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git 
a/wicket-core-tests/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java
 
b/wicket-core-tests/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java
index 4ff4456566..d70d7ac20d 100644
--- 
a/wicket-core-tests/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java
+++ 
b/wicket-core-tests/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java
@@ -186,5 +186,8 @@ class RequestUtilsTest
 
                request.setCharacterEncoding("FOO");
                assertEquals(StandardCharsets.UTF_8, 
RequestUtils.getCharset(request));
+
+               request.setCharacterEncoding("!!invalid!!");
+               assertEquals(StandardCharsets.UTF_8, 
RequestUtils.getCharset(request));
        }
 }
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java
index c7a28c317b..6b581255ff 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/RequestUtils.java
@@ -17,6 +17,7 @@
 package org.apache.wicket.protocol.http;
 
 import java.nio.charset.Charset;
+import java.nio.charset.IllegalCharsetNameException;
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.UnsupportedCharsetException;
 import java.util.ArrayList;
@@ -210,7 +211,7 @@ public final class RequestUtils
         * @param request
         *            the http servlet request to extract the charset from
         * @return the request's charset or a default it request is {@code 
null} or has an unsupported
-        *         character encoding
+        *         or malformed character encoding
         * 
         * @see 
org.apache.wicket.settings.RequestCycleSettings#getResponseRequestEncoding()
         */
@@ -226,7 +227,7 @@ public final class RequestUtils
                                {
                                        charset = Charset.forName(charsetName);
                                }
-                               catch (UnsupportedCharsetException useDefault)
+                               catch (UnsupportedCharsetException | 
IllegalCharsetNameException useDefault)
                                {
                                }
                        }

Reply via email to