Skip to content

Ignore RFC 2231 extended parameters in parse_options_header#291

Merged
Kludex merged 2 commits into
mainfrom
ignore-rfc2231-extended-params
May 31, 2026
Merged

Ignore RFC 2231 extended parameters in parse_options_header#291
Kludex merged 2 commits into
mainfrom
ignore-rfc2231-extended-params

Conversation

@Kludex
Copy link
Copy Markdown
Owner

@Kludex Kludex commented May 31, 2026

parse_options_header parsed Content-Type/Content-Disposition headers with email.message.Message, which transparently applies RFC 2231/5987 decoding: a filename*=utf-8''value parameter is percent-decoded and surfaced under the bare filename key, name* likewise, and filename*0/filename*1 continuations are reassembled. RFC 7578 §4.2 states this extended syntax MUST NOT be used in multipart/form-data.

This replaces email.message.Message with a small vendored copy of the stdlib's email.message._parseparam to split the header into its ;-separated parts (correctly ignoring ; inside quoted strings), and then ignores any *-suffixed parameter. The plain name/filename is now authoritative, matching urllib.parse, browsers, and other compliant parsers - none of which emit the extended form.

Beyond ignoring the extended parameters, behaviour is unchanged: content-type casing, quoted values, backslash unquoting, the IE6 path fix, and parameter casing all match the previous implementation. Dropping Message also removes the fuzz-driven try/except around get_params() and its Python 3.12-only special case.

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.

Replace `email.message.Message` with a small vendored `_parseparam`
splitter and ignore the RFC 5987/2231 extended syntax (`name*`,
`filename*`, and their continuations), keeping the plain parameter
authoritative per RFC 7578 §4.2.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 31, 2026

Merging this PR will not alter performance

✅ 5 untouched benchmarks


Comparing ignore-rfc2231-extended-params (a23db0f) with main (d69df35)

Open in CodSpeed

@Kludex Kludex merged commit 3506c15 into main May 31, 2026
15 checks passed
@Kludex Kludex deleted the ignore-rfc2231-extended-params branch May 31, 2026 13:44
@Kludex Kludex mentioned this pull request May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant