email.utils.decode_params not supporting params that contain hyphens
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
The decode_params function from email.utils is failing to combine the parameters from multiple lines if the name of the parameter includes a hyphen "-". Maybe it's this regex which is too strict: https://github.com/python/cpython/blob/9d1e668e6f40967dda5cbb1ce298bf0dff2d807c/Lib/email/utils.py#L392-L393
The decode_params function always ignores the first 2-tuple but the first parameter in a SMTP header can already be a multiline parameter. I don't see a reason why the first array element is skipped here:
https://github.com/python/cpython/blob/9d1e668e6f40967dda5cbb1ce298bf0dff2d807c/Lib/email/utils.py#L398-L405
my code to reproduce:
from email.utils import decode_params
decode_params([('parameter-name*0*',"utf-8''start;"),("parameter-name*1*","-middle-;"),("parameter-name*2*","end;")])
# parameter-name is not combined:
# [('parameter-name*0*', "utf-8''start;"), ('parameter-name*1*', '"-middle-;"'), ('parameter-name*2*', '"end;"')]
decode_params([('parametername*0*',"utf-8''start;"),("parametername*1*","-middle-;"),("parametername*2*","end;")])
# parametername is combined but not the first 2-tuple:
# [('parametername*0*', "utf-8''start;"), ('parametername', (None, None, '"-middle-;end;"'))]
decode_params([("ignored","ignored"),('parametername*0*',"utf-8''start;"),("parametername*1*","-middle-;"),("parametername*2*","end;")])
# parametername is now combined as expected, the additional entry can be ignored when processing the output
# [('ignored', 'ignored'), ('parametername', ('utf-8', '', '"start;-middle-;end;"'))]
Thank you
Michael
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
- gh-153536
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/utils.py tại decode_params và kiểm tra việc phân tích cú pháp tên tham số xung quanh biểu thức chính quy được tham chiếu cũng như cách xử lý tuple ban đầu. Tái hiện ba ví dụ trong issue, sau đó so sánh hành vi với PR được liên kết gh-153536. Hoàn tất khi tên tham số có dấu gạch nối và tham số nhiều dòng đầu tiên được xử lý nhất quán mà không gây hồi quy đối với các trường hợp hiện có.
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
- 35/100