[Python-checkins] cpython: #12818: remove escaping of () in quoted strings in formataddr

r.david.murray python-checkins at python.org
Wed Mar 14 20:32:50 CET 2012


http://hg.python.org/cpython/rev/ec191c51a15f
changeset:   75633:ec191c51a15f
user:        R David Murray <rdmurray at bitdance.com>
date:        Wed Mar 14 15:31:47 2012 -0400
summary:
  #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.

files:
  Lib/email/utils.py                |   2 +-
  Lib/test/test_email/test_email.py |  14 +++++++++++++-
  Misc/NEWS                         |   3 +++
  3 files changed, 17 insertions(+), 2 deletions(-)


diff --git a/Lib/email/utils.py b/Lib/email/utils.py
--- a/Lib/email/utils.py
+++ b/Lib/email/utils.py
@@ -55,7 +55,7 @@
 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
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -2702,7 +2702,10 @@
     def test_escape_dump(self):
         self.assertEqual(
             utils.formataddr(('A (Very) Silly Person', 'person at dom.ain')),
-            r'"A \(Very\) Silly Person" <person at dom.ain>')
+            r'"A (Very) Silly Person" <person at dom.ain>')
+        self.assertEqual(
+            utils.parseaddr(r'"A \(Very\) Silly Person" <person at dom.ain>'),
+            ('A (Very) Silly Person', 'person at dom.ain'))
         a = r'A \(Special\) Person'
         b = 'person at dom.ain'
         self.assertEqual(utils.parseaddr(utils.formataddr((a, b))), (a, b))
@@ -2800,6 +2803,15 @@
         self.assertEqual(('', 'merwok.wok.wok at xample.com'),
             utils.parseaddr('merwok. wok .  wok at xample.com'))
 
+    def test_formataddr_does_not_quote_parens_in_quoted_string(self):
+        addr = ("'foo at example.com' (foo at example.com)",
+                'foo at example.com')
+        addrstr = ('"\'foo at example.com\' '
+                            '(foo at example.com)" <foo at 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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -24,6 +24,9 @@
 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.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list