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.encode() crashes with IndexError on spaces only value
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Tim.Graham, barry, r.david.murray
Priority: normal Keywords: patch

Created on 2016-08-11 13:51 by Tim.Graham, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
whitespace-header-test.diff Tim.Graham, 2016-08-11 13:51 regression test for cpython's test suite review
Pull Requests
URL Status Linked Edit
PR 13478 merged BTaskaya, 2019-05-21 23:28
PR 13517 merged miss-islington, 2019-05-23 01:13
Messages (4)
msg272447 - (view) Author: Tim Graham (Tim.Graham) * Date: 2016-08-11 13:51
Python 2.7:
>>> from email.header import Header
>>> Header(' ').encode()
''

Python 3.2+ (I didn't check older versions of Python 3):
>>> Header(' ').encode()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tim/code/cpython/Lib/email/header.py", line 391, in encode
    value = formatter._str(linesep)
  File "/home/tim/code/cpython/Lib/email/header.py", line 427, in _str
    self.newline()
  File "/home/tim/code/cpython/Lib/email/header.py", line 439, in newline
    self._lines[-1] += str(self._current_line)
IndexError: list index out of range

(Originally reported at https://code.djangoproject.com/ticket/27051)
msg343262 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2019-05-23 01:13
New changeset ef5bb25e2d6147cd44be9c9b166525fb30485be0 by R. David Murray (Batuhan Taşkaya) in branch 'master':
bpo-27737: Allow whitespace only headers encoding (#13478)
https://github.com/python/cpython/commit/ef5bb25e2d6147cd44be9c9b166525fb30485be0
msg343264 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2019-05-23 01:17
Thanks.
msg343269 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2019-05-23 01:41
New changeset 0416d6f05a96e0f1b3751aa97abfffe6d3323976 by R. David Murray (Miss Islington (bot)) in branch '3.7':
bpo-27737: Allow whitespace only headers encoding (GH-13478) (#13517)
https://github.com/python/cpython/commit/0416d6f05a96e0f1b3751aa97abfffe6d3323976
History
Date User Action Args
2022-04-11 14:58:34adminsetgithub: 71924
2019-05-23 01:41:47r.david.murraysetmessages: + msg343269
2019-05-23 01:17:21r.david.murraysetstatus: open -> closed
versions: + Python 3.7, Python 3.8, - Python 3.4, Python 3.5, Python 3.6
messages: + msg343264

resolution: fixed
stage: patch review -> resolved
2019-05-23 01:13:46miss-islingtonsetpull_requests: + pull_request13434
2019-05-23 01:13:30r.david.murraysetmessages: + msg343262
2019-05-21 23:28:19BTaskayasetstage: needs patch -> patch review
pull_requests: + pull_request13390
2016-08-11 13:58:56SilentGhostsetnosy: + barry, r.david.murray
stage: needs patch
type: behavior

versions: - Python 3.2, Python 3.3
2016-08-11 13:51:04Tim.Grahamcreate