[Python-checkins] r72943 - in python/branches/py3k: Lib/test/test_urllib.py Lib/urllib/parse.py Misc/NEWS

georg.brandl python-checkins at python.org
Tue May 26 20:31:11 CEST 2009


Author: georg.brandl
Date: Tue May 26 20:31:11 2009
New Revision: 72943

Log:
#6118: dont ignore encoding arguments for arguments with spaces in quote_plus().

Modified:
   python/branches/py3k/Lib/test/test_urllib.py
   python/branches/py3k/Lib/urllib/parse.py
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Lib/test/test_urllib.py
==============================================================================
--- python/branches/py3k/Lib/test/test_urllib.py	(original)
+++ python/branches/py3k/Lib/test/test_urllib.py	Tue May 26 20:31:11 2009
@@ -510,6 +510,21 @@
         self.assertEqual(expect, result,
                          "using quote(): %r != %r" % (expect, result))
 
+    def test_quote_plus_with_unicode(self):
+        # Encoding (latin-1) test for quote_plus
+        given = "\xa2\xd8 \xff"
+        expect = "%A2%D8+%FF"
+        result = urllib.parse.quote_plus(given, encoding="latin-1")
+        self.assertEqual(expect, result,
+                         "using quote_plus(): %r != %r" % (expect, result))
+        # Errors test for quote_plus
+        given = "ab\u6f22\u5b57 cd"
+        expect = "ab%3F%3F+cd"
+        result = urllib.parse.quote_plus(given, encoding="latin-1",
+                                         errors="replace")
+        self.assertEqual(expect, result,
+                         "using quote_plus(): %r != %r" % (expect, result))
+
 class UnquotingTests(unittest.TestCase):
     """Tests for unquote() and unquote_plus()
 

Modified: python/branches/py3k/Lib/urllib/parse.py
==============================================================================
--- python/branches/py3k/Lib/urllib/parse.py	(original)
+++ python/branches/py3k/Lib/urllib/parse.py	Tue May 26 20:31:11 2009
@@ -488,7 +488,7 @@
         space = ' '
     else:
         space = b' '
-    string = quote(string, safe + space)
+    string = quote(string, safe + space, encoding, errors)
     return string.replace(' ', '+')
 
 def quote_from_bytes(bs, safe='/'):

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Tue May 26 20:31:11 2009
@@ -34,6 +34,9 @@
 Library
 -------
 
+- Issue #6118: urllib.parse.quote_plus ignored the encoding and errors
+  arguments for strings with a space in them.
+
 - In unittest, using a skipping decorator on a class is now equivalent to
   skipping every test on the class.  The ClassTestSuite class has been removed.
 


More information about the Python-checkins mailing list