From d15af0d2257bc2b1de110544f96ef769d16c4bc7 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 25 Jan 2018 20:48:24 -0500 Subject: [PATCH 1/5] adding patch set 3 to master for bpo-27931 --- Lib/email/_header_value_parser.py | 8 +++++++- .../test_email/test__header_value_parser.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py index b34c58bf85d5b49..d2d1f5cb5f3d8ad 100644 --- a/Lib/email/_header_value_parser.py +++ b/Lib/email/_header_value_parser.py @@ -430,7 +430,10 @@ def route(self): def addr_spec(self): for x in self: if x.token_type == 'addr-spec': - return x.addr_spec + if x.local_part: + return x.addr_spec + else: + return quote_string(x.local_part) + x.addr_spec else: return '<>' @@ -1164,6 +1167,9 @@ def get_bare_quoted_string(value): "expected '\"' but found '{}'".format(value)) bare_quoted_string = BareQuotedString() value = value[1:] + if value[0] == '"': + token, value = get_qcontent(value) + bare_quoted_string.append(token) while value and value[0] != '"': if value[0] in WSP: token, value = get_fws(value) diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py index 1667617b9e465f1..5cdc4bcecad4476 100644 --- a/Lib/test/test_email/test__header_value_parser.py +++ b/Lib/test/test_email/test__header_value_parser.py @@ -490,6 +490,10 @@ def test_get_bare_quoted_string_must_start_with_dquote(self): with self.assertRaises(errors.HeaderParseError): parser.get_bare_quoted_string(' "foo"') + def test_get_bare_quoted_string_only_quotes(self): + self._test_get_x(parser.get_bare_quoted_string, + '""', '""', '', [], '') + def test_get_bare_quoted_string_following_wsp_preserved(self): self._test_get_x(parser.get_bare_quoted_string, '"foo"\t bar', '"foo"', 'foo', [], '\t bar') @@ -1467,6 +1471,19 @@ def test_get_angle_addr_empty(self): self.assertIsNone(angle_addr.route) self.assertEqual(angle_addr.addr_spec, '<>') + def test_get_angle_addr_qs_only_quotes(self): + angle_addr = self._test_get_x(parser.get_angle_addr, + '<""@example.com>', + '<""@example.com>', + '<""@example.com>', + [], + '') + self.assertEqual(angle_addr.token_type, 'angle-addr') + self.assertEqual(angle_addr.local_part, '') + self.assertEqual(angle_addr.domain, 'example.com') + self.assertIsNone(angle_addr.route) + self.assertEqual(angle_addr.addr_spec, '""@example.com') + def test_get_angle_addr_with_cfws(self): angle_addr = self._test_get_x(parser.get_angle_addr, ' (foo) (bar)', From 2440d94d5fb924b7e86f8c0ee141e5c987d3f8a9 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 25 Jan 2018 21:07:44 -0500 Subject: [PATCH 2/5] added missing news for bpo-27931 --- .../NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931-e4r52t.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931-e4r52t.rst diff --git a/Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931-e4r52t.rst b/Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931-e4r52t.rst new file mode 100644 index 000000000000000..9f06b4a96a93840 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931-e4r52t.rst @@ -0,0 +1 @@ +Email parse IndexError <""@wiarcom.com> patch made by xiang.zhang From e104d7593660576c107998ace44b8c802be11c0e Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 25 Jan 2018 21:10:24 -0500 Subject: [PATCH 3/5] fixed name of file news file --- ...-27931-e4r52t.rst => 2018-01-25-21-04-11.bpo-27931.e4r52t.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Misc/NEWS.d/next/Library/{2018-01-25-21-04-11.bpo-27931-e4r52t.rst => 2018-01-25-21-04-11.bpo-27931.e4r52t.rst} (100%) diff --git a/Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931-e4r52t.rst b/Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931.e4r52t.rst similarity index 100% rename from Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931-e4r52t.rst rename to Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931.e4r52t.rst From ed4caaa6d3ef153e1d8a9f3446faeef052924b5c Mon Sep 17 00:00:00 2001 From: jayyyin Date: Thu, 25 Jan 2018 21:24:04 -0500 Subject: [PATCH 4/5] applied requested changes to discription in news file --- .../next/Library/2018-01-25-21-04-11.bpo-27931.e4r52t.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931.e4r52t.rst b/Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931.e4r52t.rst index 9f06b4a96a93840..a9092a957badf54 100644 --- a/Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931.e4r52t.rst +++ b/Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931.e4r52t.rst @@ -1 +1 @@ -Email parse IndexError <""@wiarcom.com> patch made by xiang.zhang +Fix email address header parsing error when the username is an empty quoted string. Patch by xian.zhang. From db79f314cd959ae8f8544c6f453decbe6e82928d Mon Sep 17 00:00:00 2001 From: jayyyin Date: Thu, 25 Jan 2018 21:26:24 -0500 Subject: [PATCH 5/5] fixed typo in name --- .../next/Library/2018-01-25-21-04-11.bpo-27931.e4r52t.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931.e4r52t.rst b/Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931.e4r52t.rst index a9092a957badf54..7324247357a6133 100644 --- a/Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931.e4r52t.rst +++ b/Misc/NEWS.d/next/Library/2018-01-25-21-04-11.bpo-27931.e4r52t.rst @@ -1 +1 @@ -Fix email address header parsing error when the username is an empty quoted string. Patch by xian.zhang. +Fix email address header parsing error when the username is an empty quoted string. Patch by Xiang Zhang.