mediatype: dedup parameters by exact name, not substring - #406
Merged
jhillyerd merged 1 commit intoJul 30, 2026
Merged
Conversation
fixMangledMediaType dropped a distinct parameter whenever its "<name>=" token was a substring of the accumulated parameter string -- most often when the name is a suffix of an earlier one (name after filename, id after uuid, type after subtype) or appears inside an earlier value. This silently discarded valid parameters that Go's mime.ParseMediaType keeps; e.g. `filename="a"; name="b"` lost `name`, dropping attachment filenames. Track seen parameter names in an exact, case-insensitive set (RFC 2045 section 5.1) so only true duplicate keys are removed, preserving the jhillyerd#162 behavior of collapsing exact repeats.
Owner
|
Nice, thanks |
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.
fixMangledMediaTypededuplicates media-type parameters (added for #162) with a substring test:mtypeis the parameter section accumulated so far, so a distinct parameter is dropped whenever its"<name>="token appears in the earlier text — usually when the name is a suffix of an earlier one (nameafterfilename,idafteruuid,typeaftersubtype), or when"<name>="occurs inside an earlier value. Sincefilenameandnameco-occur in most attachment headers,application/octet-stream; filename="a"; name="b"losesnameand the attachment filename is silently discarded.These are all well-formed RFC 2045 headers that Go's
mime.ParseMediaTypereturns intact, so it's a clean oracle for the intended result:Fix: track seen parameter names in an exact, case-insensitive set (RFC 2045 §5.1 makes names case-insensitive) and skip only true duplicate keys. Exact repeats still collapse (the #162 behavior); distinct parameters are kept.
I diffed a broader well-formed battery (varied param order, quoted values containing
;/=, RFC 2231 extended params, encoded-words) againstmime.ParseMediaType— the substring dedup was the only divergence;fixUnquotedSpecials,fixUnescapedQuotesandremoveTrailingHTMLTagsmatched stdlib on every well-formed input. (#401 edits the same file but a different seam — RFC 2231 multi-segment reassembly — not this dedup.)Added
TestParseMediaType/TestFixMangledMediaTypecases plus an end-to-endReadPartstest asserting the attachmentFileNamesurvives.go test ./...passes.