From 31e984c39cc7171f58878f772d0c9ad234893b2a Mon Sep 17 00:00:00 2001 From: "R. David Murray" Date: Fri, 1 Oct 2010 15:40:20 +0000 Subject: [PATCH] #10004: in Q encoded word ignore '=xx' when xx is not valid hex. Bug report and fix by Thomas Guettler. --- Lib/email/quoprimime.py | 2 +- Lib/email/test/test_email.py | 6 ++++++ Misc/NEWS | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Lib/email/quoprimime.py b/Lib/email/quoprimime.py index 12df028838..168dfffa47 100644 --- a/Lib/email/quoprimime.py +++ b/Lib/email/quoprimime.py @@ -294,4 +294,4 @@ def header_decode(s): the high level email.header class for that functionality. """ s = s.replace('_', ' ') - return re.sub(r'=\w{2}', _unquote_match, s, re.ASCII) + return re.sub(r'=[a-fA-F0-9]{2}', _unquote_match, s, re.ASCII) diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index e18ffaf9f5..b6e4831a04 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -1659,6 +1659,12 @@ Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar =?mac-iceland?q?r=8Aksm?= dh = decode_header(s % q) self.assertEqual(dh, [(a, 'iso-8859-1')]) + def test_rfc2047_Q_invalid_digits(self): + # issue 10004. + s = '=?iso-8659-1?Q?andr=e9=zz?=' + self.assertEqual(decode_header(s), + [(b'andr\xe9=zz', 'iso-8659-1')]) + # Test the MIMEMessage class class TestMIMEMessage(TestEmailBase): diff --git a/Misc/NEWS b/Misc/NEWS index 8e99376af4..3aa6a6d43a 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -79,6 +79,9 @@ Core and Builtins Library ------- +- Issue #10004: quoprimime no longer generates a traceback when confronted + with invalid characters after '=' in a Q-encoded word. + - Issue #1491: BaseHTTPServer nows send a 100 Continue response before sending a 200 OK for the Expect: 100-continue request header. -- 2.40.0