From 2bdec7bfb0b200db64c7170c0aebdf2aa5356167 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 10 Sep 2005 14:30:09 +0000 Subject: Revert 1.170. Add tests. --- Lib/test/test_urllib.py | 6 ++++++ Lib/urllib.py | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 3621476..94f0f9e 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -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() diff --git a/Lib/urllib.py b/Lib/urllib.py index 113b828..a49b586 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -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. -- cgit v0.12