Conversation
A part's `charset` was applied to the parameter name as well as to the body. The query parser compares the name against ASCII literals, so a charset that is not ASCII compatible (`UTF-16LE`, `UTF-7`) made parsing fail with `Rack::QueryParser::IncompatibleEncodingError`. The name now falls back to UTF-8 in that case; the body keeps the charset. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes #2510, following up on @jeremyevans' reply there.
tag_multipart_encodingapplies a part'scharsetto the parameter name as well as tothe body. The query parser compares that name against ASCII literals (
name.index('[', 1)),so a charset that is not ASCII compatible —
UTF-16LE, or a dummy encoding such asUTF-7that
REENCODE_DUMMY_ENCODINGSdoes not cover — makes parsing fail withRack::QueryParser::IncompatibleEncodingError. The name now falls back to UTF-8 in thatcase; the body keeps the charset it was given.
The check sits at the end of
handle_dummy_encodingbecause that is the one point everymultipart name passes, after ISO-2022-JP has been transcoded; putting it in
tag_multipart_encodingwould mean duplicating knowledge ofREENCODE_DUMMY_ENCODINGSthere. It re-tags rather than transcodes on purpose:
name.encode(Encoding::UTF_8)raisesfor a dummy encoding like UTF-7, and for a UTF-16LE name with an odd byte count.
UTF-8, Shift_JIS, ISO-2022-JP and unknown charsets are unaffected.
One existing test changes:
spec_method_override.rb"writes error to RACK_ERRORS whenusing incompatible multipart encoding" (added in #2416) asserts exactly this case as a
rejection, so it now asserts the opposite. Flagging it explicitly since it walks back part
of a change in the same unreleased cycle — happy to drop this PR if you would rather keep
those parts rejected.
The new fixture covers all three shapes in one body: a flat name, a nested
nested[text]name, and a dummy encoding. Both new tests fail without the parser change.
🤖 Generated with Claude Code