bpo-42967: coerce bytes separator to string in urllib.parse_qs(l) (#24818)
* coerce bytes separator to string
* Add news
* Update Misc/NEWS.d/next/Library/2021-03-11-00-31-41.bpo-42967.2PeQRw.rst
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
index 3b1c360..c543ac9 100644
--- a/Lib/test/test_urlparse.py
+++ b/Lib/test/test_urlparse.py
@@ -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):
@@ -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):
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
index 335e183..21cae47 100644
--- a/Lib/urllib/parse.py
+++ b/Lib/urllib/parse.py
@@ -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.")