Fix issue9301 - handle unquote({}) kind of case.

This commit is contained in:
Senthil Kumaran 2010-07-30 19:34:36 +00:00
parent 0a9c3e91dc
commit d496c4c936
2 changed files with 5 additions and 7 deletions

View File

@ -527,6 +527,7 @@ class QuotingTests(unittest.TestCase):
self.assertEqual(expect, result, self.assertEqual(expect, result,
"using quote_plus(): %r != %r" % (expect, result)) "using quote_plus(): %r != %r" % (expect, result))
class UnquotingTests(unittest.TestCase): class UnquotingTests(unittest.TestCase):
"""Tests for unquote() and unquote_plus() """Tests for unquote() and unquote_plus()
@ -555,6 +556,7 @@ class UnquotingTests(unittest.TestCase):
"using unquote(): not all characters escaped: " "using unquote(): not all characters escaped: "
"%s" % result) "%s" % result)
self.assertRaises(TypeError, urllib.parse.unquote, None) self.assertRaises(TypeError, urllib.parse.unquote, None)
self.assertRaises(TypeError, urllib.parse.unquote, ())
def test_unquoting_badpercent(self): def test_unquoting_badpercent(self):
# Test unquoting on bad percent-escapes # Test unquoting on bad percent-escapes
@ -589,8 +591,8 @@ class UnquotingTests(unittest.TestCase):
result = urllib.parse.unquote_to_bytes(given) result = urllib.parse.unquote_to_bytes(given)
self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r" self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r"
% (expect, result)) % (expect, result))
self.assertRaises(TypeError, urllib.parse.unquote_to_bytes, None) self.assertRaises(TypeError, urllib.parse.unquote_to_bytes, None)
self.assertRaises(TypeError, urllib.parse.unquote_to_bytes, ())
def test_unquoting_mixed_case(self): def test_unquoting_mixed_case(self):
# Test unquoting on mixed-case hex digits in the percent-escapes # Test unquoting on mixed-case hex digits in the percent-escapes

View File

@ -313,9 +313,7 @@ def unquote_to_bytes(string):
"""unquote_to_bytes('abc%20def') -> b'abc def'.""" """unquote_to_bytes('abc%20def') -> b'abc def'."""
# Note: strings are encoded as UTF-8. This is only an issue if it contains # Note: strings are encoded as UTF-8. This is only an issue if it contains
# unescaped non-ASCII characters, which URIs should not. # unescaped non-ASCII characters, which URIs should not.
if not string: if string in (b'', ''):
if string is None:
raise TypeError('None object is invalid for unquote_to_bytes()')
return b'' return b''
if isinstance(string, str): if isinstance(string, str):
string = string.encode('utf-8') string = string.encode('utf-8')
@ -340,9 +338,7 @@ def unquote(string, encoding='utf-8', errors='replace'):
unquote('abc%20def') -> 'abc def'. unquote('abc%20def') -> 'abc def'.
""" """
if not string: if string in (b'', ''):
if string is None:
raise TypeError('None object is invalid for unquote() function.')
return string return string
res = string.split('%') res = string.split('%')
if len(res) == 1: if len(res) == 1: