Skip to content

Commit b44a0b7

Browse files
committed
Update comment for getaddresses() and fix broken email test
1 parent d8d2831 commit b44a0b7

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Lib/email/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,18 @@ def _post_parse_validation(parsed_email_header_tuples):
131131

132132
def getaddresses(fieldvalues):
133133
"""Return a list of (REALNAME, EMAIL) or ('','') for each fieldvalue.
134-
134+
135135
When parsing fails for a fieldvalue, a 2-tuple of ('', '') is returned in
136136
its place.
137137
138-
If the resulting list is greater than number of items in the fieldvalues
139-
list, a list containing a single empty 2-tuple [('', '')] will be returned.
138+
If the resulting list of parsed address is greater than number of
139+
fieldvalues in the input list a parsing error has occurred, so a list
140+
containing a single empty 2-tuple [('', '')] is returned in its place.
141+
This is done to avoid invalid output.
142+
143+
Malformed input: getaddresses(['[email protected] <[email protected]>'])
144+
Invalid output: [('', '[email protected]'), ('', '[email protected]')]
145+
Safe output: [('', '')]
140146
"""
141147
fieldvalues = [str(v) for v in fieldvalues]
142148
fieldvalues = _pre_parse_validation(fieldvalues)

Lib/test/test_email/test_email.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3402,7 +3402,7 @@ def test_getaddresses_nasty(self):
34023402
[('', '')])
34033403
eq(utils.getaddresses(
34043404
[r'<[email protected]>, "Giant; \"Big\" Box" <[email protected]>']),
3405-
[('', '[email protected]'), ('Giant; Big Box', '[email protected]')])
3405+
[('', '[email protected]'), ('Giant; "Big" Box', '[email protected]')])
34063406

34073407
def test_getaddresses_embedded_comment(self):
34083408
"""Test proper handling of a nested comment"""

0 commit comments

Comments
 (0)