email.utils.decode_params not supporting params that contain hyphens
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 Lib/email/utils.py 中的 decode_params 開始,檢查所參照正規表示式附近的參數名稱解析,以及初始 tuple 的處理。重現 issue 中的三個範例,然後將行為與連結的 PR gh-153536 進行比較。完成的標準是:帶連字號的參數名稱和第一個多行參數能夠獲得一致處理,同時不會使現有情況發生回歸。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100