Skip to content

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
apache:masterfrom
17krishna8:charset-name-invalid
Open

17krishna8 wants to merge 1 commit into
apache:masterfrom
17krishna8:charset-name-invalid

Conversation

@17krishna8

Copy link
Copy Markdown

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 in RequestUtils.getCharset().

The name comes from the character encoding of the servlet request, which a client influences through the charset parameter of the Content-Type header (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.

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 reiern70 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@17krishna8

Copy link
Copy Markdown
Author

Thanks! I left the multipart part for a follow-up so this one can go in as is: #1677.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.96%. Comparing base (5cbd566) to head (95492d8).
⚠️ Report is 2 commits behind head on master.

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants