bpo-32498: urllib.parse.unquote also accepts bytes (GH-7768) · python/cpython@aad2ee0 (original) (raw)

`@@ -1049,8 +1049,6 @@ def test_unquoting(self):

`

1049

1049

`"%s" % result)

`

1050

1050

`self.assertRaises((TypeError, AttributeError), urllib.parse.unquote, None)

`

1051

1051

`self.assertRaises((TypeError, AttributeError), urllib.parse.unquote, ())

`

1052

``

`-

with support.check_warnings(('', BytesWarning), quiet=True):

`

1053

``

`-

self.assertRaises((TypeError, AttributeError), urllib.parse.unquote, b'')

`

1054

1052

``

1055

1053

`def test_unquoting_badpercent(self):

`

1056

1054

`# Test unquoting on bad percent-escapes

`

`@@ -1210,6 +1208,29 @@ def test_unquote_with_unicode(self):

`

1210

1208

`self.assertEqual(expect, result,

`

1211

1209

`"using unquote(): %r != %r" % (expect, result))

`

1212

1210

``

``

1211

`+

def test_unquoting_with_bytes_input(self):

`

``

1212

`+

ASCII characters decoded to a string

`

``

1213

`+

given = b'blueberryjam'

`

``

1214

`+

expect = 'blueberryjam'

`

``

1215

`+

result = urllib.parse.unquote(given)

`

``

1216

`+

self.assertEqual(expect, result,

`

``

1217

`+

"using unquote(): %r != %r" % (expect, result))

`

``

1218

+

``

1219

`+

A mix of non-ASCII hex-encoded characters and ASCII characters

`

``

1220

`+

given = b'bl\xc3\xa5b\xc3\xa6rsyltet\xc3\xb8y'

`

``

1221

`+

expect = 'bl\u00e5b\u00e6rsyltet\u00f8y'

`

``

1222

`+

result = urllib.parse.unquote(given)

`

``

1223

`+

self.assertEqual(expect, result,

`

``

1224

`+

"using unquote(): %r != %r" % (expect, result))

`

``

1225

+

``

1226

`+

A mix of non-ASCII percent-encoded characters and ASCII characters

`

``

1227

`+

given = b'bl%c3%a5b%c3%a6rsyltet%c3%b8j'

`

``

1228

`+

expect = 'bl\u00e5b\u00e6rsyltet\u00f8j'

`

``

1229

`+

result = urllib.parse.unquote(given)

`

``

1230

`+

self.assertEqual(expect, result,

`

``

1231

`+

"using unquote(): %r != %r" % (expect, result))

`

``

1232

+

``

1233

+

1213

1234

`class urlencode_Tests(unittest.TestCase):

`

1214

1235

`"""Tests for urlencode()"""

`

1215

1236

``