Skip to content

Commit 5be0eaa

Browse files
committed
Add test case
1 parent 901a91c commit 5be0eaa

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Lib/test/test_email/test_email.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,23 @@ def test_nonascii_add_header_with_tspecial(self):
728728
"attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.ppt",
729729
msg['Content-Disposition'])
730730

731+
def test_invalid_headers(self):
732+
invalid_headers = [
733+
('Invalid Header', 'Contains space'),
734+
('Tab\tHeader', 'Contains tab'),
735+
('Colon:Header', 'Contains colon'),
736+
('', 'Empty name'),
737+
('Header\x7F', 'Non-ASCII character'),
738+
('Header\x1F', 'Control character'),
739+
(' LeadingSpace', 'Starts with space'),
740+
('TrailingSpace ', 'Ends with space'),
741+
]
742+
for name, value in invalid_headers:
743+
with self.subTest(header=name):
744+
with self.assertRaises(ValueError) as cm:
745+
self.message.add_header(name, value)
746+
self.assertIn("Invalid header", str(cm.exception))
747+
731748
def test_binary_quopri_payload(self):
732749
for charset in ('latin-1', 'ascii'):
733750
msg = Message()

0 commit comments

Comments
 (0)