email.utils.decode_params not supporting params that contain hyphens
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
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
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/utils.py at decode_params and inspect the parameter-name parsing around the referenced regex and initial tuple handling. Reproduce the three examples from the issue, then compare behavior with the linked PR gh-153536. Done means hyphenated parameter names and a first multiline parameter are handled consistently without regressing the existing cases.
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
- 35/100