diff options
author | Irit Katriel <iritkatriel@yahoo.com> | 2020-10-18 21:06:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-18 21:06:34 (GMT) |
commit | 1a3f7c042a32fb813835243bd7f96e47c665bfdc (patch) | |
tree | b115c0e1011c068090718a41759217071ed481aa /Lib | |
parent | 1040299e9283609f3de0f6e32a0d43458fe7f4f6 (diff) | |
download | cpython-1a3f7c042a32fb813835243bd7f96e47c665bfdc.zip cpython-1a3f7c042a32fb813835243bd7f96e47c665bfdc.tar.gz cpython-1a3f7c042a32fb813835243bd7f96e47c665bfdc.tar.bz2 |
[3.8] bpo-32498: Improve exception message on passing bytes to urllib.parse.unquote (GH-22746)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_urllib.py | 6 | ||||
-rw-r--r-- | Lib/urllib/parse.py | 2 |
2 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 1c247c5..8626687 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -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()""" diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py index e2b6f13..95be718 100644 --- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -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 |