Make charset parameter name comparison case-insensitive - #474
Open
rootkiller6788 wants to merge 1 commit into
Open
Make charset parameter name comparison case-insensitive#474rootkiller6788 wants to merge 1 commit into
rootkiller6788 wants to merge 1 commit into
Conversation
HTTP header parameter names are case-insensitive per RFC 7230, so a Content-Type of "text/plain; Charset=UTF-8" should be recognized the same as "charset=utf-8". Previously only the exact lowercase form was matched, causing the charset to be ignored and the response to be decoded with the default ISO-8859-1 encoding (or the passed-in default), garbling non-ASCII text in StringRequest responses.
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.
Problem
HttpHeaderParser.parseCharset()only matches the exact lowercasecharsetparameter name when parsing aContent-Typeheader:HTTP header parameter names are case-insensitive (RFC 7230 section 3.2.6). A server that emits e.g.
Content-Type: text/plain; Charset=UTF-8orCHARSET=UTF-8therefore has its charset silently ignored, and the response body falls back to the default encoding. ForStringRequestthe default isISO-8859-1, so any non-ASCII text (e.g. UTF-8 JSON or localized content) is decoded as mojibake.Fix
Compare the parameter name with
equalsIgnoreCasesocharset,Charset, andCHARSETare all recognized, matching the case-insensitivity of the rest of header handling in Volley (header names are already looked up case-insensitively via aTreeMapwithString.CASE_INSENSITIVE_ORDER).Verification
Content-Type: text/plain; Charset=UTF-8returnedISO-8859-1; after the fix it returnsUTF-8.CHARSET=Shift_JISis also recognized.HttpHeaderParserTest.parseCharset()for mixed- and upper-casecharsetparameter names.