From d496c4c9360b481ca68b68b6bba6b6687136e442 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Fri, 30 Jul 2010 19:34:36 +0000 Subject: [PATCH] Fix issue9301 - handle unquote({}) kind of case. --- Lib/test/test_urllib.py | 4 +++- Lib/urllib/parse.py | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 44574c9c145..23492fb3bb7 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -527,6 +527,7 @@ class QuotingTests(unittest.TestCase): self.assertEqual(expect, result, "using quote_plus(): %r != %r" % (expect, result)) + class UnquotingTests(unittest.TestCase): """Tests for unquote() and unquote_plus() @@ -555,6 +556,7 @@ class UnquotingTests(unittest.TestCase): "using unquote(): not all characters escaped: " "%s" % result) self.assertRaises(TypeError, urllib.parse.unquote, None) + self.assertRaises(TypeError, urllib.parse.unquote, ()) def test_unquoting_badpercent(self): # Test unquoting on bad percent-escapes @@ -589,8 +591,8 @@ class UnquotingTests(unittest.TestCase): result = urllib.parse.unquote_to_bytes(given) self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r" % (expect, result)) - self.assertRaises(TypeError, urllib.parse.unquote_to_bytes, None) + self.assertRaises(TypeError, urllib.parse.unquote_to_bytes, ()) def test_unquoting_mixed_case(self): # Test unquoting on mixed-case hex digits in the percent-escapes diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py index 691c004831a..a9fa26ad8f6 100644 --- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -313,9 +313,7 @@ def unquote_to_bytes(string): """unquote_to_bytes('abc%20def') -> b'abc def'.""" # Note: strings are encoded as UTF-8. This is only an issue if it contains # unescaped non-ASCII characters, which URIs should not. - if not string: - if string is None: - raise TypeError('None object is invalid for unquote_to_bytes()') + if string in (b'', ''): return b'' if isinstance(string, str): string = string.encode('utf-8') @@ -340,9 +338,7 @@ def unquote(string, encoding='utf-8', errors='replace'): unquote('abc%20def') -> 'abc def'. """ - if not string: - if string is None: - raise TypeError('None object is invalid for unquote() function.') + if string in (b'', ''): return string res = string.split('%') if len(res) == 1: