fall back to utf-8 for invalid content-type charset#3427
Merged
Conversation
Response.charset() and feign-form's FormEncoder.getCharset() passed the parsed charset token straight to Charset.forName, so an unsupported or illegal name from a Content-Type header threw instead of using the documented UTF-8 default. Catch the charset exceptions in both and fall back to UTF-8, as FeignException.getResponseCharset already does.
velo
approved these changes
Jun 19, 2026
velo
left a comment
Member
There was a problem hiding this comment.
This is a focused fix: Response.charset() and FormEncoder now both fall back to UTF-8 for illegal or unsupported charset tokens, and the new tests cover the two failure paths in core and feign-form. I do not see a compatibility or security issue here.
Merged
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.
Repro: a server response with
Content-Type: text/plain; charset=made-up-99(or an illegal name such ascharset=@) reachesResponse.charset(), which is called by every JSON/text decoder (jackson,json,fastjson2,jackson-jr,jackson3) throughresponse.body().asReader(response.charset()).Expected:
charset()returns its documented UTF-8 default.Actual:
UnsupportedCharsetException/IllegalCharsetNameExceptionescapes the decoder on an otherwise valid response.Cause:
Response.charset()hands the charset token parsed out of the header straight toCharset.forNamewith no guard.feign-form'sFormEncoder.getCharsethas the same unguarded call on the requestContent-Type.FeignException.getResponseCharsetalready guards the identical parse.Fix: catch
IllegalCharsetNameException/UnsupportedCharsetExceptionin both helpers and fall back to UTF-8. Regression tests cover both an illegal and an unsupported charset name.