Skip to content

Commit 5bd2489

Browse files
Add test for parse_qsl strict_parsing on malformed fields
The strict_parsing=True path in urllib.parse.parse_qsl was only exercised with empty inputs, which return before the parsing loop, so its ValueError branch was untested. Add a test that a field without '=' raises ValueError under strict_parsing (str and bytes) and that well-formed input still parses.
1 parent 0023d5b commit 5bd2489

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Lib/test/test_urlparse.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,15 @@ def test_parse_qsl_false_value(self):
15271527
self.assertEqual(cm.filename, __file__)
15281528
self.assertRaises(ValueError, urllib.parse.parse_qsl, x, separator=1)
15291529

1530+
def test_parse_qsl_strict_parsing(self):
1531+
for func in (urllib.parse.parse_qsl, urllib.parse.parse_qs):
1532+
self.assertRaises(ValueError, func, 'a=1&b&c=3', strict_parsing=True)
1533+
self.assertRaises(ValueError, func, b'a=1&b', strict_parsing=True)
1534+
self.assertEqual(urllib.parse.parse_qsl('a=1&c=3', strict_parsing=True),
1535+
[('a', '1'), ('c', '3')])
1536+
self.assertEqual(urllib.parse.parse_qs('a=1&c=3', strict_parsing=True),
1537+
{'a': ['1'], 'c': ['3']})
1538+
15301539
def test_parse_qsl_errors(self):
15311540
self.assertRaises(TypeError, urllib.parse.parse_qsl, list(b'a=b'))
15321541
self.assertRaises(TypeError, urllib.parse.parse_qsl, iter(b'a=b'))

0 commit comments

Comments
 (0)