This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: email.header.Header encoding fails on empty header
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: r.david.murray Nosy List: ntkoopman, r.david.murray
Priority: normal Keywords: patch

Created on 2011-06-02 15:25 by ntkoopman, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
header.patch ntkoopman, 2011-06-02 15:25 Simple patch
Messages (5)
msg137480 - (view) Author: Tim Koopman (ntkoopman) Date: 2011-06-02 15:25
Creating an empty header produces an exception when calling the encode function:

>>> from email.header import Header
>>> Header('', 'iso-8859-1').encode()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.2/email/header.py", line 317, in encode
    formatter.feed(lines[0], charset)
IndexError: list index out of range

According to RFC822, empty headers are valid (and are found in the wild anyway), so this should just work.

I've attached a trivial fix that appears to work.
msg137482 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-06-02 15:46
I can't reproduce this.  What exact version of Python are you using?
msg137484 - (view) Author: Tim Koopman (ntkoopman) Date: 2011-06-02 16:18
The default Arch Linux version: 3.2.0

Python 3.2 (r32:88445, Apr 15 2011, 11:09:05)
msg137486 - (view) Author: Tim Koopman (ntkoopman) Date: 2011-06-02 16:27
Looking at the source of 3.2.1, it appears this was already solved. Sorry.
msg137492 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-06-02 18:56
No problem.  It's too bad that regression slipped in to 3.2.0.  I probably fixed it by accident, since I rewrote a bunch of that code in 3.2.1 while fixing a different bug.
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56450
2011-06-02 18:56:26r.david.murraysetstatus: open -> closed
resolution: out of date
messages: + msg137492

stage: resolved
2011-06-02 16:27:45ntkoopmansetmessages: + msg137486
2011-06-02 16:18:18ntkoopmansetmessages: + msg137484
2011-06-02 15:46:23r.david.murraysetassignee: r.david.murray

messages: + msg137482
nosy: + r.david.murray
2011-06-02 15:25:14ntkoopmancreate