email: unquoted apostrophe in a MIME parameter value is dropped under policy.default
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
With policy.default a parameter value containing an unquoted apostrophe is not returned, while compat32 returns it. The apostrophe is not a tspecial (RFC 2045), so a bare value such as filename=O'Brien.pdf is a valid token and should be parsed whole.
import email, email.policy
msg = email.message_from_string(
"Content-Disposition: attachment; filename=O'Brien.pdf\n\nbody\n",
policy=email.policy.default
)
msg.get_filename() is None
True
Under email.policy.compat32 the same string returns "O'Brien.pdf". Quoting the value (filename="O'Brien.pdf") works under both policies.
For a multipart message an unquoted apostrophe in the boundary is not recognized, so is_multipart() returns False and the message is not split.
ASPECIALS in Lib/email/_header_value_parser.py includes "'" unconditionally, which terminates the value.
Observed on 3.16.0a0.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-153842
- gh-153846
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Lib/email/_header_value_parser.py, where the issue identifies ASPECIALS as terminating the parameter value. Add regression coverage for an unquoted apostrophe in a Content-Disposition filename and multipart boundary, then run the relevant email parser tests and confirm both cases work under policy.default.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100