email: unquoted apostrophe in a MIME parameter value is dropped under policy.default
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Lib/email/_header_value_parser.py 开始,issue 在此处将 ASPECIALS 标识为参数值的终止符。为 Content-Disposition 文件名和 multipart boundary 中未加引号的撇号添加回归测试覆盖,然后运行相关的 email parser 测试,并确认这两种情况在 policy.default 下都能正常工作。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100