Fix charset parsing of quoted HTTP Content-Type parameters - #2543
Open
Andy (jesko2004) wants to merge 1 commit into
Open
Andy (jesko2004) wants to merge 1 commit into
Andy (jesko2004) wants to merge 1 commit into
Conversation
|
Andy (@jesko2004) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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.
convert_response()splitsContent-Typeon every semicolon, including semicolons inside quoted parameter values. For example,text/plain; charset=iso-8859-1; profile="urn:example;charset=utf-8"incorrectly overrides the real charset with UTF-8 and fails to convertb"Caf\xe9".Use the already imported standard-library
email.message.Messageto parse the charset parameter. This preserves quoted values and converts the response toCafé, without adding a dependency or changing explicitStreamInfooverrides.Nine regression and control cases use in-memory
requests.Responseobjects and the public conversion API. Against unchanged main, two cases fail and seven pass; all nine pass with this fix.Related: #1844 handles case-insensitive parameter names. This PR addresses quoted parameter boundaries; the HTTP parser hunk overlaps, while Data URI parsing is unchanged.
Validation (Windows, Python 3.12.14): full core suite 984 passed, 34 skipped with CI skip conditions; related tests 89 passed, 5 skipped;
pre-commit run --all-filesandgit diff --checkpassed.Prepared and tested with OpenAI Codex assistance.