summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-03-14 19:31:47 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-03-14 19:31:47 (GMT)
commitb53319f509be7389187a943122de9e6b479a8bf9 (patch)
tree610aa2d78a35a9bc780ab34f8e12064dd618d506
parent345266aa7e7fdbb1bbf3ffd244caff39406d46d2 (diff)
downloadcpython-b53319f509be7389187a943122de9e6b479a8bf9.zip
cpython-b53319f509be7389187a943122de9e6b479a8bf9.tar.gz
cpython-b53319f509be7389187a943122de9e6b479a8bf9.tar.bz2
#12818: remove escaping of () in quoted strings in formataddr
The quoting of ()s inside quoted strings is allowed by the RFC, but is not needed. There seems to be no reason to add needless escapes.
-rw-r--r--Lib/email/utils.py2
-rw-r--r--Lib/test/test_email/test_email.py14
-rw-r--r--Misc/NEWS3
3 files changed, 17 insertions, 2 deletions
diff --git a/Lib/email/utils.py b/Lib/email/utils.py
index aecea65..138f05d 100644
--- a/Lib/email/utils.py
+++ b/Lib/email/utils.py
@@ -55,7 +55,7 @@ CRLF = '\r\n'
TICK = "'"
specialsre = re.compile(r'[][\\()<>@,:;".]')
-escapesre = re.compile(r'[][\\()"]')
+escapesre = re.compile(r'[\\"]')
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index 1f354c2..08a49f8 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -2702,7 +2702,10 @@ class TestMiscellaneous(TestEmailBase):
def test_escape_dump(self):
self.assertEqual(
utils.formataddr(('A (Very) Silly Person', 'person@dom.ain')),
- r'"A \(Very\) Silly Person" <person@dom.ain>')
+ r'"A (Very) Silly Person" <person@dom.ain>')
+ self.assertEqual(
+ utils.parseaddr(r'"A \(Very\) Silly Person" <person@dom.ain>'),
+ ('A (Very) Silly Person', 'person@dom.ain'))
a = r'A \(Special\) Person'
b = 'person@dom.ain'
self.assertEqual(utils.parseaddr(utils.formataddr((a, b))), (a, b))
@@ -2800,6 +2803,15 @@ class TestMiscellaneous(TestEmailBase):
self.assertEqual(('', 'merwok.wok.wok@xample.com'),
utils.parseaddr('merwok. wok . wok@xample.com'))
+ def test_formataddr_does_not_quote_parens_in_quoted_string(self):
+ addr = ("'foo@example.com' (foo@example.com)",
+ 'foo@example.com')
+ addrstr = ('"\'foo@example.com\' '
+ '(foo@example.com)" <foo@example.com>')
+ self.assertEqual(utils.parseaddr(addrstr), addr)
+ self.assertEqual(utils.formataddr(addr), addrstr)
+
+
def test_multiline_from_comment(self):
x = """\
Foo
diff --git a/Misc/NEWS b/Misc/NEWS
index 45fb967..96ce07c 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -24,6 +24,9 @@ Core and Builtins
Library
-------
+- Issue #12818: format address no longer needlessly \ escapes ()s in names when
+ the name ends up being quoted.
+
- Issue #14062: BytesGenerator now correctly folds Header objects,
including using linesep when folding.