Skip to content

Commit 050491c

Browse files
committed
fixup! Fix email header wrapping omitting white space
1 parent fb23a6e commit 050491c

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Lib/email/_header_value_parser.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,9 +2840,7 @@ def _steal_all_trailing_WSP_if_exists(lines):
28402840
wsp_lines = []
28412841
while lines and lines[-1]:
28422842
for i in range(len(lines[-1]), -1, -1):
2843-
if i <= 0:
2844-
break
2845-
if lines[-1][i - 1] not in WSP:
2843+
if i <= 0 or lines[-1][i - 1] not in WSP:
28462844
break
28472845
wsp_line = lines[-1][i:]
28482846
if not wsp_line:
@@ -2854,9 +2852,8 @@ def _steal_all_trailing_WSP_if_exists(lines):
28542852
lines.pop()
28552853
else:
28562854
break
2857-
28582855
if lines_popped:
2859-
lines.append(' ')
2856+
lines.append(' ' if lines else '')
28602857
return ''.join(wsp_lines)
28612858

28622859
def _refold_parse_tree(parse_tree, *, policy):
@@ -2967,7 +2964,7 @@ def _refold_parse_tree(parse_tree, *, policy):
29672964
newline = _steal_trailing_WSP_if_exists(lines)
29682965
if newline or part.startswith_fws():
29692966
lines.append(newline + tstr)
2970-
if not all(char in WSP for char in lines[-1]):
2967+
if any(char not in WSP for char in lines[-1]):
29712968
last_word_is_ew = False
29722969
last_ew = None
29732970
continue

0 commit comments

Comments
 (0)