diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-07-11 19:58:07 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-07-11 19:58:07 (GMT) |
commit | 63194a774e47ab5c7a10a693ef53188cf24dce16 (patch) | |
tree | b2a6fa5fb2c9057a908488bb150ba12e43ab5701 /Lib/test/test_email | |
parent | f9e6672ae8044f9dbcbafe98a6b63ab30189770e (diff) | |
parent | 65171b28e77f589a490335c8749a24151e1d8817 (diff) | |
download | cpython-63194a774e47ab5c7a10a693ef53188cf24dce16.zip cpython-63194a774e47ab5c7a10a693ef53188cf24dce16.tar.gz cpython-63194a774e47ab5c7a10a693ef53188cf24dce16.tar.bz2 |
Merge: #18044: Fix parsing of encoded words of the form =?utf8?q?=XX...?=
Diffstat (limited to 'Lib/test/test_email')
-rw-r--r-- | Lib/test/test_email/test__encoded_words.py | 5 | ||||
-rw-r--r-- | Lib/test/test_email/test__header_value_parser.py | 9 | ||||
-rw-r--r-- | Lib/test/test_email/test_headerregistry.py | 41 |
3 files changed, 51 insertions, 4 deletions
diff --git a/Lib/test/test_email/test__encoded_words.py b/Lib/test/test_email/test__encoded_words.py index 14395fe..f8e380d 100644 --- a/Lib/test/test_email/test__encoded_words.py +++ b/Lib/test/test_email/test__encoded_words.py @@ -122,6 +122,11 @@ class TestDecode(TestEmailBase): # XXX Should this be a new Defect instead? defects = [errors.CharsetError]) + def test_q_nonascii(self): + self._test('=?utf-8?q?=C3=89ric?=', + 'Éric', + charset='utf-8') + class TestEncodeQ(TestEmailBase): diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py index 6101e19..8917447 100644 --- a/Lib/test/test_email/test__header_value_parser.py +++ b/Lib/test/test_email/test__header_value_parser.py @@ -170,6 +170,15 @@ class TestParser(TestParserMixin, TestEmailBase): [], '') + def test_get_encoded_word_quopri_utf_escape_follows_cte(self): + # Issue 18044 + self._test_get_x(parser.get_encoded_word, + '=?utf-8?q?=C3=89ric?=', + 'Éric', + 'Éric', + [], + '') + # get_unstructured def _get_unst(self, value): diff --git a/Lib/test/test_email/test_headerregistry.py b/Lib/test/test_email/test_headerregistry.py index c0c81c1..80f1c02 100644 --- a/Lib/test/test_email/test_headerregistry.py +++ b/Lib/test/test_email/test_headerregistry.py @@ -123,12 +123,45 @@ class TestBaseHeaderFeatures(TestHeaderBase): # self.assertEqual(h, value) # self.assertDefectsEqual(h.defects, [errors.ObsoleteHeaderDefect]) - def test_RFC2047_value_decoded(self): - value = '=?utf-8?q?this_is_a_test?=' - h = self.make_header('subject', value) - self.assertEqual(h, 'this is a test') +@parameterize +class TestUnstructuredHeader(TestHeaderBase): + def string_as_value(self, + source, + decoded, + *args): + l = len(args) + defects = args[0] if l>0 else [] + header = 'Subject:' + (' ' if source else '') + folded = header + (args[1] if l>1 else source) + '\n' + h = self.make_header('Subject', source) + self.assertEqual(h, decoded) + self.assertDefectsEqual(h.defects, defects) + self.assertEqual(h.fold(policy=policy.default), folded) + + string_params = { + + 'rfc2047_simple_quopri': ( + '=?utf-8?q?this_is_a_test?=', + 'this is a test', + [], + 'this is a test'), + + 'rfc2047_gb2312_base64': ( + '=?gb2312?b?1eLKx9bQzsSy4srUo6E=?=', + '\u8fd9\u662f\u4e2d\u6587\u6d4b\u8bd5\uff01', + [], + '=?utf-8?b?6L+Z5piv5Lit5paH5rWL6K+V77yB?='), + + 'rfc2047_simple_nonascii_quopri': ( + '=?utf-8?q?=C3=89ric?=', + 'Éric'), + + } + + +@parameterize class TestDateHeader(TestHeaderBase): datestring = 'Sun, 23 Sep 2001 20:10:55 -0700' |