Repository navigation
Fall back to the default charset when the request charset name is not a legal name - #1675
Open
17krishna8 wants to merge 1 commit into
Open
17krishna8 wants to merge 1 commit into
17krishna8 wants to merge 1 commit into
Conversation
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.
reiern70
approved these changes
Oct 17, 2026
reiern70
left a comment
Contributor
There was a problem hiding this comment.
Thanks, looks good. On master RequestUtils.getCharset() throws IllegalCharsetNameException for !!invalid!!; with the change it falls back to the default, as it already does for an unknown name.
Optional, same pattern: MultipartServletWebRequestImpl reads request.getCharacterEncoding() (line 151) and passes it to Charset.forName() (around lines 213 and 334) without catching either exception. Fine to cover it here, or leave it for a follow-up.
Author
|
Thanks! I left the multipart part for a follow-up so this one can go in as is: #1677. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1675 +/- ##
=========================================
Coverage 61.96% 61.96%
- Complexity 11285 11286 +1
=========================================
Files 1250 1250
Lines 48437 48437
Branches 6796 6796
=========================================
+ Hits 30014 30015 +1
Misses 15729 15729
+ Partials 2694 2693 -1 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Charset.forName()throwsIllegalCharsetNameExceptionfor a name that is not even a legal charset name, next toUnsupportedCharsetExceptionfor a legal but unknown one, and only the latter was caught inRequestUtils.getCharset().The name comes from the character encoding of the servlet request, which a client influences through the charset parameter of the
Content-Typeheader (whether such a name reaches the application differs between containers), so the value could surface as an unhandled runtime exception while the request charset is resolved.Both exceptions are now handled the same way: the encoding is unknown and the default charset is used.