Repository navigation
middleware: parse quoted ContentCharset media parameters - #1218
Merged
Merged
Conversation
Drop the hand-written quoted-pair normalizer and the httptest-based test from the original change. mime.ParseMediaType handles quoted charset values on its own, and the table test covers the remaining cases in-process. Co-Authored-By: tianrking <10758833+tianrking@users.noreply.github.com> Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Vojtech Vitek <vojtech.vitek@golang.cz>
Rename the backslash row to describe what it tests, and add rows for xcharset (not a charset parameter) and a malformed parameter that falls back to the legacy parser. Document quoted charset values on ContentCharset. Co-Authored-By: tianrking <10758833+tianrking@users.noreply.github.com> Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Vojtech Vitek <vojtech.vitek@golang.cz>
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.
Summary
ContentCharsetrejects valid quoted charset values such asContent-Type: text/plain; charset="UTF-8"with a 415. It also readscharset=from inside an earlier quoted parameter. This PR switches the lookup tomime.ParseMediaTypeand keeps the old lenient parsing as a fallback for headers that are not valid media types.Attribution
The first commit is the work from go-chi/chi#1205 by @tianrking, applied unchanged. It keeps the original author, commit message, and validation. Credit for the fix belongs to them.
The second commit simplifies that change after review of #1205.
What the second commit changes
normalizeHTTPQuotedPairs(about 25 lines). It only handles backslash-escaped non-special characters such ascharset="UTF\-8", which no real client sends.TestContentCharsetMediaParametersOverHTTP. It tests chunked framing, not charset parsing, and the in-process table test covers the logic.quoted pairrow from the table test.Notes
mime.ParseMediaTypeadds one map allocation per request.charset = utf-8andcharset*=UTF-8''utf-8.strings.Trimfix. It was closed without merging. This change also handles the quoted;cases that fix(middleware): accept quoted charset in Content-Type #1139 does not.Testing
go vet ./middlewarego test -race ./middleware🤖 This message was generated by Claude on behalf of Vojtech.