Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
srinivasreddy committed Dec 17, 2024
1 parent ce18c9b commit aaa8879
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def test_nonascii_add_header_with_tspecial(self):
"attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.ppt",
msg['Content-Disposition'])

def test_invalid_headers(self):
def test_invalid_header_names(self):
invalid_headers = [
('Invalid Header', 'contains space'),
('Tab\tHeader', 'contains tab'),
Expand All @@ -738,18 +738,20 @@ def test_invalid_headers(self):
('TrailingSpace ', 'ends with space'),
]
for name, value in invalid_headers:
with self.assertRaises(ValueError) as cm:
Message().add_header(name, value)
self.assertIn(f"Invalid header field name {name!r}", str(cm.exception))
with self.subTest(name=name, problem=value):
with self.assertRaises(ValueError) as cm:
Message().add_header(name, value)
self.assertIn(f"Invalid header field name {name!r}", str(cm.exception))

invalid_headers = [
('Header\x7F', 'Non-ASCII character'),
('Header\x1F', 'control character'),
]
for name, value in invalid_headers:
with self.assertRaises(ValueError) as cm:
Message().add_header(name, value)
self.assertIn(f"Invalid header field name {name!r}", str(cm.exception))
with self.subTest(name=name, problem=value):
with self.assertRaises(ValueError) as cm:
Message().add_header(name, value)
self.assertIn(f"Header field name contains invalid characters: {name!r}", str(cm.exception))

def test_binary_quopri_payload(self):
for charset in ('latin-1', 'ascii'):
Expand Down

0 comments on commit aaa8879

Please sign in to comment.