]> granicus.if.org Git - python/commitdiff
#12818: remove escaping of () in quoted strings in formataddr
authorR David Murray <rdmurray@bitdance.com>
Wed, 14 Mar 2012 19:31:47 +0000 (15:31 -0400)
committerR David Murray <rdmurray@bitdance.com>
Wed, 14 Mar 2012 19:31:47 +0000 (15:31 -0400)
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.

Lib/email/utils.py
Lib/test/test_email/test_email.py
Misc/NEWS

index aecea656e66ac9064aabe82d8c8396b7c436dffb..138f05dfdb3aebb3d49295e585618121da9834e0 100644 (file)
@@ -55,7 +55,7 @@ CRLF = '\r\n'
 TICK = "'"
 
 specialsre = re.compile(r'[][\\()<>@,:;".]')
-escapesre = re.compile(r'[][\\()"]')
+escapesre = re.compile(r'[\\"]')
 
 
 
index 1f354c2b66028728e5137f3bc22c69698c988647..08a49f8d586364584f52c96c09ed2bb6106b007f 100644 (file)
@@ -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
index 45fb9672f0d36399e22b1155d79c02d0f1ec17f3..96ce07c3af9fb86a46689441f2b3893cf2d29391 100644 (file)
--- 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.