Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
66edb629
Commit
66edb629
authored
Jul 19, 2004
by
Neil Schemenauer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't return spurious empty fields if 'keep_empty_values' is True.
Fixes SF bug #990307.
parent
36a0f89c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
2 deletions
+38
-2
Lib/cgi.py
Lib/cgi.py
+2
-0
Lib/test/output/test_cgi
Lib/test/output/test_cgi
+11
-0
Lib/test/test_cgi.py
Lib/test/test_cgi.py
+21
-2
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Lib/cgi.py
View file @
66edb629
...
@@ -209,6 +209,8 @@ def parse_qsl(qs, keep_blank_values=0, strict_parsing=0):
...
@@ -209,6 +209,8 @@ def parse_qsl(qs, keep_blank_values=0, strict_parsing=0):
pairs
=
[
s2
for
s1
in
qs
.
split
(
'&'
)
for
s2
in
s1
.
split
(
';'
)]
pairs
=
[
s2
for
s1
in
qs
.
split
(
'&'
)
for
s2
in
s1
.
split
(
';'
)]
r
=
[]
r
=
[]
for
name_value
in
pairs
:
for
name_value
in
pairs
:
if
not
name_value
and
not
strict_parsing
:
continue
nv
=
name_value
.
split
(
'='
,
1
)
nv
=
name_value
.
split
(
'='
,
1
)
if
len
(
nv
)
!=
2
:
if
len
(
nv
)
!=
2
:
if
strict_parsing
:
if
strict_parsing
:
...
...
Lib/test/output/test_cgi
View file @
66edb629
test_cgi
test_cgi
'' => []
'&' => []
'&&' => []
'=' => [('', '')]
'=a' => [('', 'a')]
'a' => [('a', '')]
'a=' => [('a', '')]
'a=' => [('a', '')]
'&a=b' => [('a', 'b')]
'a=a+b&b=b+c' => [('a', 'a b'), ('b', 'b c')]
'a=1&a=2' => [('a', '1'), ('a', '2')]
''
''
'&'
'&'
'&&'
'&&'
...
...
Lib/test/test_cgi.py
View file @
66edb629
...
@@ -55,7 +55,21 @@ def do_test(buf, method):
...
@@ -55,7 +55,21 @@ def do_test(buf, method):
# A list of test cases. Each test case is a a two-tuple that contains
# A list of test cases. Each test case is a a two-tuple that contains
# a string with the query and a dictionary with the expected result.
# a string with the query and a dictionary with the expected result.
parse_test_cases
=
[
parse_qsl_test_cases
=
[
(
""
,
[]),
(
"&"
,
[]),
(
"&&"
,
[]),
(
"="
,
[(
''
,
''
)]),
(
"=a"
,
[(
''
,
'a'
)]),
(
"a"
,
[(
'a'
,
''
)]),
(
"a="
,
[(
'a'
,
''
)]),
(
"a="
,
[(
'a'
,
''
)]),
(
"&a=b"
,
[(
'a'
,
'b'
)]),
(
"a=a+b&b=b+c"
,
[(
'a'
,
'a b'
),
(
'b'
,
'b c'
)]),
(
"a=1&a=2"
,
[(
'a'
,
'1'
),
(
'a'
,
'2'
)]),
]
parse_strict_test_cases
=
[
(
""
,
ValueError
(
"bad query field: ''"
)),
(
""
,
ValueError
(
"bad query field: ''"
)),
(
"&"
,
ValueError
(
"bad query field: ''"
)),
(
"&"
,
ValueError
(
"bad query field: ''"
)),
(
"&&"
,
ValueError
(
"bad query field: ''"
)),
(
"&&"
,
ValueError
(
"bad query field: ''"
)),
...
@@ -114,7 +128,12 @@ def first_second_elts(list):
...
@@ -114,7 +128,12 @@ def first_second_elts(list):
return
map
(
lambda
p
:(
p
[
0
],
p
[
1
][
0
]),
list
)
return
map
(
lambda
p
:(
p
[
0
],
p
[
1
][
0
]),
list
)
def
main
():
def
main
():
for
orig
,
expect
in
parse_test_cases
:
for
orig
,
expect
in
parse_qsl_test_cases
:
result
=
cgi
.
parse_qsl
(
orig
,
keep_blank_values
=
True
)
print
repr
(
orig
),
'=>'
,
result
verify
(
result
==
expect
,
"Error parsing %s"
%
repr
(
orig
))
for
orig
,
expect
in
parse_strict_test_cases
:
# Test basic parsing
# Test basic parsing
print
repr
(
orig
)
print
repr
(
orig
)
d
=
do_test
(
orig
,
"GET"
)
d
=
do_test
(
orig
,
"GET"
)
...
...
Misc/NEWS
View file @
66edb629
...
@@ -94,6 +94,10 @@ Library
...
@@ -94,6 +94,10 @@ Library
-
The
threading
module
has
a
new
class
,
local
,
for
creating
objects
-
The
threading
module
has
a
new
class
,
local
,
for
creating
objects
that
provide
thread
-
local
data
.
that
provide
thread
-
local
data
.
-
Bug
#
990307
:
when
keep_empty_values
is
True
,
cgi
.
parse_qsl
()
no
longer
returns
spurious
empty
fields
.
Tools
/
Demos
Tools
/
Demos
-----------
-----------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment