]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.8] bpo-32498: Improve exception message on passing bytes to urllib.parse.unquote...
authorIrit Katriel <iritkatriel@yahoo.com>
Sun, 18 Oct 2020 21:06:34 +0000 (22:06 +0100)
committerGitHub <noreply@github.com>
Sun, 18 Oct 2020 21:06:34 +0000 (00:06 +0300)
Lib/test/test_urllib.py
Lib/urllib/parse.py
Misc/NEWS.d/next/Library/2020-10-18-19-22-39.bpo-32498.MoqSgo.rst [new file with mode: 0644]

index 1c247c5d1543a20cadb99235572b1d50b9e935a8..8626687151185e3140516d592a31a3534739d928 100644 (file)
@@ -1245,6 +1245,12 @@ class UnquotingTests(unittest.TestCase):
         self.assertEqual(expect, result,
                          "using unquote(): %r != %r" % (expect, result))
 
+    def test_unquoting_with_bytes_input(self):
+        # Bytes not supported yet
+        with self.assertRaisesRegex(TypeError, 'Expected str, got bytes'):
+            given = b'bl\xc3\xa5b\xc3\xa6rsyltet\xc3\xb8y'
+            urllib.parse.unquote(given)
+
 class urlencode_Tests(unittest.TestCase):
     """Tests for urlencode()"""
 
index e2b6f133e1cd9c7478a28e71fa8630051eb4bae4..95be7181133b4b62b9bf56ddb5a7b4d42bf6fd83 100644 (file)
@@ -631,6 +631,8 @@ def unquote(string, encoding='utf-8', errors='replace'):
 
     unquote('abc%20def') -> 'abc def'.
     """
+    if isinstance(string, bytes):
+        raise TypeError('Expected str, got bytes')
     if '%' not in string:
         string.split
         return string
diff --git a/Misc/NEWS.d/next/Library/2020-10-18-19-22-39.bpo-32498.MoqSgo.rst b/Misc/NEWS.d/next/Library/2020-10-18-19-22-39.bpo-32498.MoqSgo.rst
new file mode 100644 (file)
index 0000000..3083ded
--- /dev/null
@@ -0,0 +1,3 @@
+Clearer exception message when passing an argument of type bytes to
+:func:`urllib.parse.unquote`.  This is only for 3.8; in 3.9 and later this
+function accepts bytes inputs as well.  PR by Irit Katriel.