]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Revert 1.170. Add tests.
authorRaymond Hettinger <python@rcn.com>
Sat, 10 Sep 2005 14:30:09 +0000 (14:30 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 10 Sep 2005 14:30:09 +0000 (14:30 +0000)
Lib/test/test_urllib.py
Lib/urllib.py

index 36214767bdad3775ea76976b0aa8001d9781b922..94f0f9efb9bbeec2e707f0471de35e82150d6e03 100644 (file)
@@ -353,6 +353,12 @@ class QuotingTests(unittest.TestCase):
         self.assertEqual(expect, result,
                          "using quote_plus(): %s != %s" % (expect, result))
 
+    def test_quoting_plus(self):
+        self.assertEqual(urllib.quote_plus('alpha+beta gamma'),
+                         'alpha%2Bbeta+gamma')
+        self.assertEqual(urllib.quote_plus('alpha+beta gamma', '+'),
+                         'alpha+beta+gamma')
+
 class UnquotingTests(unittest.TestCase):
     """Tests for unquote() and unquote_plus()
 
index 113b828dc69e3ca14ef6f366e5190a34b7ea47a6..a49b5865920b65224a073bf3ed2f7bbf7320c88c 100644 (file)
@@ -1110,9 +1110,12 @@ def quote(s, safe = '/'):
 def quote_plus(s, safe = ''):
     """Quote the query fragment of a URL; replacing ' ' with '+'"""
     if ' ' in s:
-        s = s.replace(' ', '+')
-        safe += '+'
-    return quote(s, safe)
+        l = s.split(' ')
+        for i in range(len(l)):
+            l[i] = quote(l[i], safe)
+        return '+'.join(l)
+    else:
+        return quote(s, safe)
 
 def urlencode(query,doseq=0):
     """Encode a sequence of two-element tuples or dictionary into a URL query string.