gh-116897: Deprecate generic false values in urllib.parse.parse_qsl() (GH-116903)

Accepting objects with false values (like 0 and []) except empty strings
and byte-like objects and None in urllib.parse functions parse_qsl() and
parse_qs() is now deprecated.
This commit is contained in:
Serhiy Storchaka 2024-11-12 21:10:29 +02:00 committed by GitHub
parent 03924b5dee
commit 7577307ebd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 45 additions and 9 deletions

View file

@ -1314,9 +1314,17 @@ class UrlParseTestCase(unittest.TestCase):
def test_parse_qsl_false_value(self):
kwargs = dict(keep_blank_values=True, strict_parsing=True)
for x in '', b'', None, 0, 0.0, [], {}, memoryview(b''):
for x in '', b'', None, memoryview(b''):
self.assertEqual(urllib.parse.parse_qsl(x, **kwargs), [])
self.assertRaises(ValueError, urllib.parse.parse_qsl, x, separator=1)
for x in 0, 0.0, [], {}:
with self.assertWarns(DeprecationWarning) as cm:
self.assertEqual(urllib.parse.parse_qsl(x, **kwargs), [])
self.assertEqual(cm.filename, __file__)
with self.assertWarns(DeprecationWarning) as cm:
self.assertEqual(urllib.parse.parse_qs(x, **kwargs), {})
self.assertEqual(cm.filename, __file__)
self.assertRaises(ValueError, urllib.parse.parse_qsl, x, separator=1)
def test_parse_qsl_errors(self):
self.assertRaises(TypeError, urllib.parse.parse_qsl, list(b'a=b'))