From 8d13e6a9720cb2e7345baa67d670f34c7df53aff Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Tue, 3 Oct 2017 21:45:09 +0900 Subject: [PATCH 1/2] bpo-31677: email: Add re.ASCII flag to re.compile() While there is not real bug in this case, using re.ASCII is safe when re.IGNORECASE is used. This commit removes dead copy in email.util too. --- Lib/email/header.py | 2 +- Lib/email/utils.py | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/Lib/email/header.py b/Lib/email/header.py index c7b2dd9f310b01..315a617991f6a4 100644 --- a/Lib/email/header.py +++ b/Lib/email/header.py @@ -40,7 +40,7 @@ \? # literal ? (?P.*?) # non-greedy up to the next ?= is the encoded string \?= # literal ?= - ''', re.VERBOSE | re.IGNORECASE | re.MULTILINE) + ''', re.VERBOSE | re.IGNORECASE | re.ASCII | re.MULTILINE) # Field name regexp, including trailing colon, but not separating whitespace, # according to RFC 2822. Character range is from tilde to exclamation mark. diff --git a/Lib/email/utils.py b/Lib/email/utils.py index 39c22406078074..858f620e25bfb0 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -114,18 +114,6 @@ def getaddresses(fieldvalues): return a.addresslist - -ecre = re.compile(r''' - =\? # literal =? - (?P[^?]*?) # non-greedy up to the next ? is the charset - \? # literal ? - (?P[qb]) # either a "q" or a "b", case insensitive - \? # literal ? - (?P.*?) # non-greedy up to the next ?= is the atom - \?= # literal ?= - ''', re.VERBOSE | re.IGNORECASE) - - def _format_timetuple_and_zone(timetuple, zone): return '%s, %02d %s %04d %02d:%02d:%02d %s' % ( ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][timetuple[6]], From 08a5034144a956db2e86f6718970f02931a12768 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Wed, 4 Oct 2017 01:13:06 +0900 Subject: [PATCH 2/2] remove re.IGNORECASE --- Lib/email/header.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/email/header.py b/Lib/email/header.py index 315a617991f6a4..7b30a039da1c46 100644 --- a/Lib/email/header.py +++ b/Lib/email/header.py @@ -36,11 +36,11 @@ =\? # literal =? (?P[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? - (?P[qb]) # either a "q" or a "b", case insensitive + (?P[qQbB]) # either a "q" or a "b", case insensitive \? # literal ? (?P.*?) # non-greedy up to the next ?= is the encoded string \?= # literal ?= - ''', re.VERBOSE | re.IGNORECASE | re.ASCII | re.MULTILINE) + ''', re.VERBOSE | re.MULTILINE) # Field name regexp, including trailing colon, but not separating whitespace, # according to RFC 2822. Character range is from tilde to exclamation mark.