forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpo-40944: Fix IndexError when parse emails with truncated Message-ID…
…, address, routes, etc (pythonGH-20790) Co-authored-by: Serhiy Storchaka <[email protected]>
- Loading branch information
1 parent
147cd05
commit 1aa8bbe
Showing
3 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -801,6 +801,10 @@ def test_get_quoted_string_header_ends_in_qcontent(self): | |
self.assertEqual(qs.content, 'bob') | ||
self.assertEqual(qs.quoted_value, ' "bob"') | ||
|
||
def test_get_quoted_string_cfws_only_raises(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_quoted_string(' (foo) ') | ||
|
||
def test_get_quoted_string_no_quoted_string(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_quoted_string(' (ab) xyz') | ||
|
@@ -1135,6 +1139,10 @@ def test_get_local_part_complex_obsolete_invalid(self): | |
'@python.org') | ||
self.assertEqual(local_part.local_part, 'Fred.A.Johnson and dogs') | ||
|
||
def test_get_local_part_empty_raises(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_local_part('') | ||
|
||
def test_get_local_part_no_part_raises(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_local_part(' (foo) ') | ||
|
@@ -1387,6 +1395,10 @@ def test_get_domain_obsolete(self): | |
'') | ||
self.assertEqual(domain.domain, 'example.com') | ||
|
||
def test_get_domain_empty_raises(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_domain("") | ||
|
||
def test_get_domain_no_non_cfws_raises(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_domain(" (foo)\t") | ||
|
@@ -1512,6 +1524,10 @@ def test_get_obs_route_no_route_before_end_raises(self): | |
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_obs_route('(foo) @example.com,') | ||
|
||
def test_get_obs_route_no_route_before_end_raises2(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_obs_route('(foo) @example.com, (foo) ') | ||
|
||
def test_get_obs_route_no_route_before_special_raises(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_obs_route('(foo) [abc],') | ||
|
@@ -1520,6 +1536,14 @@ def test_get_obs_route_no_route_before_special_raises2(self): | |
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_obs_route('(foo) @example.com [abc],') | ||
|
||
def test_get_obs_route_no_domain_after_at_raises(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_obs_route('@') | ||
|
||
def test_get_obs_route_no_domain_after_at_raises2(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_obs_route('@example.com, @') | ||
|
||
# get_angle_addr | ||
|
||
def test_get_angle_addr_simple(self): | ||
|
@@ -1646,6 +1670,14 @@ def test_get_angle_addr_ends_at_special(self): | |
self.assertIsNone(angle_addr.route) | ||
self.assertEqual(angle_addr.addr_spec, '[email protected]') | ||
|
||
def test_get_angle_addr_empty_raise(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_angle_addr('') | ||
|
||
def test_get_angle_addr_left_angle_only_raise(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_angle_addr('<') | ||
|
||
def test_get_angle_addr_no_angle_raise(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_angle_addr('(foo) ') | ||
|
@@ -1857,6 +1889,10 @@ def test_get_name_addr_ends_at_special(self): | |
self.assertIsNone(name_addr.route) | ||
self.assertEqual(name_addr.addr_spec, '[email protected]') | ||
|
||
def test_get_name_addr_empty_raises(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_name_addr('') | ||
|
||
def test_get_name_addr_no_content_raises(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_name_addr(' (foo) ') | ||
|
@@ -2732,6 +2768,10 @@ def test_get_msg_id_empty_id_right(self): | |
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_msg_id("<simplelocal@>") | ||
|
||
def test_get_msg_id_no_id_right(self): | ||
with self.assertRaises(errors.HeaderParseError): | ||
parser.get_msg_id("<simplelocal@") | ||
|
||
def test_get_msg_id_with_brackets(self): | ||
# Microsof Outlook generates non-standard one-off addresses: | ||
# https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/one-off-addresses | ||
|
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2020-06-10-19-24-17.bpo-40943.vjiiN_.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix several IndexError when parse emails with truncated Message-ID, address, routes, etc, e.g. ``example@``. |