]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42967: coerce bytes separator to string in urllib.parse_qs(l) (#24818)
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Sun, 11 Apr 2021 13:26:09 +0000 (21:26 +0800)
committerGitHub <noreply@github.com>
Sun, 11 Apr 2021 13:26:09 +0000 (06:26 -0700)
* coerce bytes separator to string

* Add news

* Update Misc/NEWS.d/next/Library/2021-03-11-00-31-41.bpo-42967.2PeQRw.rst

Lib/test/test_urlparse.py
Lib/urllib/parse.py
Misc/NEWS.d/next/Library/2021-03-11-00-31-41.bpo-42967.2PeQRw.rst [new file with mode: 0644]

index 3b1c360625b5a63218d75f6bd2cbffaa546d517d..c543ac9a4ba72eae8938e9d44b2bd70d11412d7c 100644 (file)
@@ -893,6 +893,8 @@ class UrlParseTestCase(unittest.TestCase):
             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 @@ class UrlParseTestCase(unittest.TestCase):
             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):
index 335e183498d8bd5ea1c29142b54c60c36c31c09a..21cae47bf38a3654fab6e39f5311e05ffc0860d7 100644 (file)
@@ -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.")
diff --git a/Misc/NEWS.d/next/Library/2021-03-11-00-31-41.bpo-42967.2PeQRw.rst b/Misc/NEWS.d/next/Library/2021-03-11-00-31-41.bpo-42967.2PeQRw.rst
new file mode 100644 (file)
index 0000000..f8ad3ea
--- /dev/null
@@ -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``.