summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cgi.py
diff options
context:
space:
mode:
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>2004-07-19 15:38:11 (GMT)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>2004-07-19 15:38:11 (GMT)
commit66edb6295f956af9c559ef037c5016c9f6b64261 (patch)
tree8aa6adeef3e152e189752fab16046dfe477bb306 /Lib/test/test_cgi.py
parent36a0f89c37f535254043712168cd9c0a4f1a7f40 (diff)
downloadcpython-66edb6295f956af9c559ef037c5016c9f6b64261.zip
cpython-66edb6295f956af9c559ef037c5016c9f6b64261.tar.gz
cpython-66edb6295f956af9c559ef037c5016c9f6b64261.tar.bz2
Don't return spurious empty fields if 'keep_empty_values' is True.
Fixes SF bug #990307.
Diffstat (limited to 'Lib/test/test_cgi.py')
-rw-r--r--Lib/test/test_cgi.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py
index 980e3b6..5ecaf7f 100644
--- a/Lib/test/test_cgi.py
+++ b/Lib/test/test_cgi.py
@@ -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 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: ''")),
@@ -114,7 +128,12 @@ def first_second_elts(list):
return map(lambda p:(p[0], p[1][0]), list)
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
print repr(orig)
d = do_test(orig, "GET")