Skip to content

Commit 8447ed5

Browse files
committed
Address review: fix comment style and move test
1 parent 328bbac commit 8447ed5

3 files changed

Lines changed: 14 additions & 16 deletions

File tree

Lib/email/_header_value_parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,8 +2792,7 @@ def _steal_trailing_WSP_if_exists(lines):
27922792
if lines and lines[-1] and lines[-1][-1] in WSP:
27932793
wsp = lines[-1][-1]
27942794
lines[-1] = lines[-1][:-1]
2795-
# FIX: If the line is now empty (it was only a space), remove it entirely
2796-
# to prevent creating an empty line (double newline) in the output.
2795+
# gh-142006: if the line is now empty, remove it entirely.
27972796
if not lines[-1]:
27982797
lines.pop()
27992798
return wsp

Lib/test/test_email/test__header_value_parser.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,5 +3255,18 @@ def test_long_filename_attachment(self):
32553255
" filename*1*=_TEST_TES.txt\n",
32563256
)
32573257

3258+
def test_fold_unfoldable_element_stealing_whitespace(self):
3259+
# gh-142006: When an element is too long to fit on the current line
3260+
# the previous line's trailing whitespace
3261+
policy = self.policy.clone(max_line_length=10)
3262+
3263+
# "a," fits. The space after it should wrap to the next line.
3264+
# The "long" part (20 chars) forces the wrap because 20 > 10.
3265+
text = "a, " + ("b" * 20)
3266+
expected = "a,\n " + ("b" * 20) + "\n"
3267+
3268+
token = parser.get_address_list(text)[0]
3269+
self._test(token, expected, policy=policy)
3270+
32583271
if __name__ == '__main__':
32593272
unittest.main()

Lib/test/test_email/test_policy.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,6 @@ def test_fold_zero_max_line_length(self):
165165
self.assertEqual(p1.fold('Subject', msg['Subject']), expected)
166166
self.assertEqual(p2.fold('Subject', msg['Subject']), expected)
167167

168-
def test_fold_address_list_with_stolen_whitespace(self):
169-
long_address = (
170-
"loooooooooooooooooooooooooooooooooooong@dooooooooooooomainname.example.com, "
171-
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.example.com"
172-
)
173-
msg = email.message_from_string(f"To: {long_address}\n\n", policy=email.policy.default)
174-
175-
# This should not raise HeaderWriteError
176-
output = msg.as_string()
177-
# Verify the output format is correct and clean
178-
self.assertIn(long_address.split(',')[0], output)
179-
# Ensure header section doesn't have double newlines
180-
self.assertNotIn('\n\n', output.split('\n\n')[0])
181-
182168
def test_register_defect(self):
183169
class Dummy:
184170
def __init__(self):

0 commit comments

Comments
 (0)