summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_urlparse.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-03-05 15:49:50 (GMT)
committerGitHub <noreply@github.com>2024-03-05 15:49:50 (GMT)
commitbdba8ef42b15e651dc23374a08143cc2b4c4657d (patch)
tree8af049682491f0bb9bd8c49b0f7886b5544fb9c4 /Lib/test/test_urlparse.py
parentf97f25ef5dfcdfec0d9a359fd970abd139cf3428 (diff)
downloadcpython-bdba8ef42b15e651dc23374a08143cc2b4c4657d.zip
cpython-bdba8ef42b15e651dc23374a08143cc2b4c4657d.tar.gz
cpython-bdba8ef42b15e651dc23374a08143cc2b4c4657d.tar.bz2
gh-74668: Fix support of bytes in urllib.parse.parse_qsl() (GH-115771)
urllib.parse functions parse_qs() and parse_qsl() now support bytes arguments containing raw and percent-encoded non-ASCII data.
Diffstat (limited to 'Lib/test/test_urlparse.py')
-rw-r--r--Lib/test/test_urlparse.py37
1 files changed, 35 insertions, 2 deletions
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
index 625c6dc..72f0286 100644
--- a/Lib/test/test_urlparse.py
+++ b/Lib/test/test_urlparse.py
@@ -19,6 +19,10 @@ parse_qsl_test_cases = [
("=a", [('', 'a')]),
("a", [('a', '')]),
("a=", [('a', '')]),
+ ("a=b=c", [('a', 'b=c')]),
+ ("a%3Db=c", [('a=b', 'c')]),
+ ("a=b&c=d", [('a', 'b'), ('c', 'd')]),
+ ("a=b%26c=d", [('a', 'b&c=d')]),
("&a=b", [('a', 'b')]),
("a=a+b&b=b+c", [('a', 'a b'), ('b', 'b c')]),
("a=1&a=2", [('a', '1'), ('a', '2')]),
@@ -29,6 +33,10 @@ parse_qsl_test_cases = [
(b"=a", [(b'', b'a')]),
(b"a", [(b'a', b'')]),
(b"a=", [(b'a', b'')]),
+ (b"a=b=c", [(b'a', b'b=c')]),
+ (b"a%3Db=c", [(b'a=b', b'c')]),
+ (b"a=b&c=d", [(b'a', b'b'), (b'c', b'd')]),
+ (b"a=b%26c=d", [(b'a', b'b&c=d')]),
(b"&a=b", [(b'a', b'b')]),
(b"a=a+b&b=b+c", [(b'a', b'a b'), (b'b', b'b c')]),
(b"a=1&a=2", [(b'a', b'1'), (b'a', b'2')]),
@@ -36,6 +44,14 @@ parse_qsl_test_cases = [
("a=a+b;b=b+c", [('a', 'a b;b=b c')]),
(b";a=b", [(b';a', b'b')]),
(b"a=a+b;b=b+c", [(b'a', b'a b;b=b c')]),
+
+ ("\u0141=\xE9", [('\u0141', '\xE9')]),
+ ("%C5%81=%C3%A9", [('\u0141', '\xE9')]),
+ ("%81=%A9", [('\ufffd', '\ufffd')]),
+ (b"\xc5\x81=\xc3\xa9", [(b'\xc5\x81', b'\xc3\xa9')]),
+ (b"%C5%81=%C3%A9", [(b'\xc5\x81', b'\xc3\xa9')]),
+ (b"\x81=\xA9", [(b'\x81', b'\xa9')]),
+ (b"%81=%A9", [(b'\x81', b'\xa9')]),
]
# Each parse_qs testcase is a two-tuple that contains
@@ -49,6 +65,10 @@ parse_qs_test_cases = [
("=a", {'': ['a']}),
("a", {'a': ['']}),
("a=", {'a': ['']}),
+ ("a=b=c", {'a': ['b=c']}),
+ ("a%3Db=c", {'a=b': ['c']}),
+ ("a=b&c=d", {'a': ['b'], 'c': ['d']}),
+ ("a=b%26c=d", {'a': ['b&c=d']}),
("&a=b", {'a': ['b']}),
("a=a+b&b=b+c", {'a': ['a b'], 'b': ['b c']}),
("a=1&a=2", {'a': ['1', '2']}),
@@ -59,6 +79,10 @@ parse_qs_test_cases = [
(b"=a", {b'': [b'a']}),
(b"a", {b'a': [b'']}),
(b"a=", {b'a': [b'']}),
+ (b"a=b=c", {b'a': [b'b=c']}),
+ (b"a%3Db=c", {b'a=b': [b'c']}),
+ (b"a=b&c=d", {b'a': [b'b'], b'c': [b'd']}),
+ (b"a=b%26c=d", {b'a': [b'b&c=d']}),
(b"&a=b", {b'a': [b'b']}),
(b"a=a+b&b=b+c", {b'a': [b'a b'], b'b': [b'b c']}),
(b"a=1&a=2", {b'a': [b'1', b'2']}),
@@ -66,6 +90,15 @@ parse_qs_test_cases = [
("a=a+b;b=b+c", {'a': ['a b;b=b c']}),
(b";a=b", {b';a': [b'b']}),
(b"a=a+b;b=b+c", {b'a':[ b'a b;b=b c']}),
+ (b"a=a%E2%80%99b", {b'a': [b'a\xe2\x80\x99b']}),
+
+ ("\u0141=\xE9", {'\u0141': ['\xE9']}),
+ ("%C5%81=%C3%A9", {'\u0141': ['\xE9']}),
+ ("%81=%A9", {'\ufffd': ['\ufffd']}),
+ (b"\xc5\x81=\xc3\xa9", {b'\xc5\x81': [b'\xc3\xa9']}),
+ (b"%C5%81=%C3%A9", {b'\xc5\x81': [b'\xc3\xa9']}),
+ (b"\x81=\xA9", {b'\x81': [b'\xa9']}),
+ (b"%81=%A9", {b'\x81': [b'\xa9']}),
]
class UrlParseTestCase(unittest.TestCase):
@@ -995,8 +1028,8 @@ class UrlParseTestCase(unittest.TestCase):
def test_parse_qsl_max_num_fields(self):
with self.assertRaises(ValueError):
- urllib.parse.parse_qs('&'.join(['a=a']*11), max_num_fields=10)
- urllib.parse.parse_qs('&'.join(['a=a']*10), max_num_fields=10)
+ urllib.parse.parse_qsl('&'.join(['a=a']*11), max_num_fields=10)
+ urllib.parse.parse_qsl('&'.join(['a=a']*10), max_num_fields=10)
def test_parse_qs_separator(self):
parse_qs_semicolon_cases = [