]> granicus.if.org Git - python/commitdiff
Fix Issue9301 - urllib.parse.unquote and unquote_to_byte to raise TypeError for None.
authorSenthil Kumaran <orsenthil@gmail.com>
Mon, 19 Jul 2010 18:17:19 +0000 (18:17 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Mon, 19 Jul 2010 18:17:19 +0000 (18:17 +0000)
Lib/test/test_urllib.py
Lib/urllib/parse.py

index e293cf0ad3e8dacb72c0f798b2cf77d5150a6e07..44574c9c14585e4b9fdde4a6b502906d679820be 100644 (file)
@@ -554,6 +554,7 @@ class UnquotingTests(unittest.TestCase):
         self.assertEqual(result.count('%'), 1,
                          "using unquote(): not all characters escaped: "
                          "%s" % result)
+        self.assertRaises(TypeError, urllib.parse.unquote, None)
 
     def test_unquoting_badpercent(self):
         # Test unquoting on bad percent-escapes
@@ -589,6 +590,8 @@ class UnquotingTests(unittest.TestCase):
         self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r"
                          % (expect, result))
 
+        self.assertRaises(TypeError, urllib.parse.unquote_to_bytes, None)
+
     def test_unquoting_mixed_case(self):
         # Test unquoting on mixed-case hex digits in the percent-escapes
         given = '%Ab%eA'
index 82edea18f44affa78d9b3c53d95d655ce843d3fe..691c004831a456e4222bd684f6142bfe88f412dc 100644 (file)
@@ -314,6 +314,8 @@ def unquote_to_bytes(string):
     # 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()')
         return b''
     if isinstance(string, str):
         string = string.encode('utf-8')
@@ -339,6 +341,8 @@ 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.')
         return string
     res = string.split('%')
     if len(res) == 1: