bpo-45874: Handle empty query string correctly in urllib.parse.parse_qsl (#29716)
This commit is contained in:
committed by
GitHub
parent
4325a766f5
commit
e6fe10d340
@@ -51,7 +51,7 @@ def do_test(buf, method):
|
||||
return ComparableException(err)
|
||||
|
||||
parse_strict_test_cases = [
|
||||
("", ValueError("bad query field: ''")),
|
||||
("", {}),
|
||||
("&", ValueError("bad query field: ''")),
|
||||
("&&", ValueError("bad query field: ''")),
|
||||
# Should the next few really be valid?
|
||||
|
||||
@@ -740,12 +740,13 @@ def parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
|
||||
# is less than max_num_fields. This prevents a memory exhaustion DOS
|
||||
# attack via post bodies with many fields.
|
||||
if max_num_fields is not None:
|
||||
num_fields = 1 + qs.count(separator)
|
||||
num_fields = 1 + qs.count(separator) if qs else 0
|
||||
if max_num_fields < num_fields:
|
||||
raise ValueError('Max number of fields exceeded')
|
||||
|
||||
r = []
|
||||
for name_value in qs.split(separator):
|
||||
query_args = qs.split(separator) if qs else []
|
||||
for name_value in query_args:
|
||||
if not name_value and not strict_parsing:
|
||||
continue
|
||||
nv = name_value.split('=', 1)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
The empty query string, consisting of no query arguments, is now handled
|
||||
correctly in ``urllib.parse.parse_qsl``. This caused problems before when
|
||||
strict parsing was enabled.
|
||||
Reference in New Issue
Block a user