[Python-checkins] r85180 - in python/branches/release31-maint: Lib/email/_parseaddr.py Lib/email/test/test_email.py Misc/NEWS
r.david.murray
python-checkins at python.org
Sat Oct 2 18:04:44 CEST 2010
Author: r.david.murray
Date: Sat Oct 2 18:04:44 2010
New Revision: 85180
Log:
Merged revisions 85179 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r85179 | r.david.murray | 2010-10-02 11:58:26 -0400 (Sat, 02 Oct 2010) | 6 lines
#1050268: make parseaddr 'quote' the contents of quoted strings in addresses.
Also made the doc string for email._parseaddr's 'quote' function more
accurate; I'd love to make the function match the old docstring instead,
but other code uses it according the existing semantics.
........
Modified:
python/branches/release31-maint/ (props changed)
python/branches/release31-maint/Lib/email/_parseaddr.py
python/branches/release31-maint/Lib/email/test/test_email.py
python/branches/release31-maint/Misc/NEWS
Modified: python/branches/release31-maint/Lib/email/_parseaddr.py
==============================================================================
--- python/branches/release31-maint/Lib/email/_parseaddr.py (original)
+++ python/branches/release31-maint/Lib/email/_parseaddr.py Sat Oct 2 18:04:44 2010
@@ -160,7 +160,12 @@
def quote(str):
- """Add quotes around a string."""
+ """Prepare string to be used in a quoted string.
+
+ Turns backslash and double quote characters into quoted pairs. These
+ are the only characters that need to be quoted inside a quoted string.
+ Does not add the surrounding double quotes.
+ """
return str.replace('\\', '\\\\').replace('"', '\\"')
@@ -318,7 +323,7 @@
aslist.append('.')
self.pos += 1
elif self.field[self.pos] == '"':
- aslist.append('"%s"' % self.getquote())
+ aslist.append('"%s"' % quote(self.getquote()))
elif self.field[self.pos] in self.atomends:
break
else:
Modified: python/branches/release31-maint/Lib/email/test/test_email.py
==============================================================================
--- python/branches/release31-maint/Lib/email/test/test_email.py (original)
+++ python/branches/release31-maint/Lib/email/test/test_email.py Sat Oct 2 18:04:44 2010
@@ -2283,6 +2283,24 @@
# formataddr() quotes the name if there's a dot in it
self.assertEqual(utils.formataddr((a, b)), y)
+ def test_parseaddr_preserves_quoted_pairs_in_addresses(self):
+ # issue 10005. Note that in the third test the second pair of
+ # backslashes is not actually a quoted pair because it is not inside a
+ # comment or quoted string: the address being parsed has a quoted
+ # string containing a quoted backslash, followed by 'example' and two
+ # backslashes, followed by another quoted string containing a space and
+ # the word 'example'. parseaddr copies those two backslashes
+ # literally. Per rfc5322 this is not technically correct since a \ may
+ # not appear in an address outside of a quoted string. It is probably
+ # a sensible Postel interpretation, though.
+ eq = self.assertEqual
+ eq(utils.parseaddr('""example" example"@example.com'),
+ ('', '""example" example"@example.com'))
+ eq(utils.parseaddr('"\\"example\\" example"@example.com'),
+ ('', '"\\"example\\" example"@example.com'))
+ eq(utils.parseaddr('"\\\\"example\\\\" example"@example.com'),
+ ('', '"\\\\"example\\\\" example"@example.com'))
+
def test_multiline_from_comment(self):
x = """\
Foo
Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS (original)
+++ python/branches/release31-maint/Misc/NEWS Sat Oct 2 18:04:44 2010
@@ -121,6 +121,9 @@
Library
-------
+- Issue #1050268: parseaddr now correctly quotes double quote and backslash
+ characters that appear inside quoted strings in email addresses.
+
- Issue #10004: quoprimime no longer generates a traceback when confronted
with invalid characters after '=' in a Q-encoded word.
More information about the Python-checkins
mailing list