Skip to content

Commit d85561d

Browse files
Add test for collapse_rfc2231_value with non-3-tuples
1 parent 3dec095 commit d85561d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Lib/test/test_email/test_email.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5789,6 +5789,21 @@ def test_should_not_hang_on_invalid_ew_messages(self):
57895789
with self.subTest(m=m):
57905790
msg = email.message_from_string(m)
57915791

5792+
def test_collapse_rfc2231_value_non_3_tuple(self):
5793+
# collapse_rfc2231_value should not crash on tuples
5794+
# whose length is not 3.
5795+
from email.utils import collapse_rfc2231_value
5796+
# Non-3-tuples should return a string, not raise AttributeError.
5797+
for val in [(), ('a',), ('a', 'b'), ('a', 'b', 'c', 'd')]:
5798+
with self.subTest(val=val):
5799+
result = collapse_rfc2231_value(val)
5800+
self.assertIsInstance(result, str)
5801+
# A proper 3-tuple decodes correctly.
5802+
result = collapse_rfc2231_value(('us-ascii', 'en', 'hello'))
5803+
self.assertEqual(result, 'hello')
5804+
# A plain string passes through unquote.
5805+
self.assertEqual(collapse_rfc2231_value('"hello"'), 'hello')
5806+
57925807

57935808
# Tests to ensure that signed parts of an email are completely preserved, as
57945809
# required by RFC1847 section 2.1. Note that these are incomplete, because the

0 commit comments

Comments
 (0)