email: unquoted apostrophe in a MIME parameter value is dropped under policy.default
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu trong Lib/email/_header_value_parser.py, nơi issue xác định ASPECIALS là ký tự kết thúc giá trị tham số. Thêm kiểm thử hồi quy cho một dấu nháy đơn không được đặt trong dấu ngoặc kép trong tên tệp Content-Disposition và multipart boundary, sau đó chạy các kiểm thử email parser liên quan và xác nhận rằng cả hai trường hợp đều hoạt động với policy.default.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 25/100