Skip to content

bpo-42967: coerce bytes separator to string in urllib.parse_qs(l) #24818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/test/test_urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,8 @@ def test_parse_qs_separator(self):
with self.subTest(f"Original: {orig!r}, Expected: {expect!r}"):
result = urllib.parse.parse_qs(orig, separator=';')
self.assertEqual(result, expect, "Error parsing %r" % orig)
result_bytes = urllib.parse.parse_qs(orig, separator=b';')
self.assertEqual(result_bytes, expect, "Error parsing %r" % orig)


def test_parse_qsl_separator(self):
Expand All @@ -912,6 +914,8 @@ def test_parse_qsl_separator(self):
with self.subTest(f"Original: {orig!r}, Expected: {expect!r}"):
result = urllib.parse.parse_qsl(orig, separator=';')
self.assertEqual(result, expect, "Error parsing %r" % orig)
result_bytes = urllib.parse.parse_qsl(orig, separator=b';')
self.assertEqual(result_bytes, expect, "Error parsing %r" % orig)


def test_urlencode_sequences(self):
Expand Down
1 change: 1 addition & 0 deletions Lib/urllib/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ def parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
Returns a list, as G-d intended.
"""
qs, _coerce_result = _coerce_args(qs)
separator, _ = _coerce_args(separator)

if not separator or (not isinstance(separator, (str, bytes))):
raise ValueError("Separator must be of type string or bytes.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Allow :class:`bytes` ``separator`` argument in ``urllib.parse.parse_qs`` and
``urllib.parse.parse_qsl`` when parsing :class:`str` query strings. Previously,
this raised a ``TypeError``.