summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-03-01 23:08:36 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-03-01 23:08:36 (GMT)
commit096f1a85f05b478c1e9aabfa23a724d882f65f2a (patch)
tree1dfe363207fb561021d7e8d5c7114d9eaacca810
parent819c40ff35aeead0f78c71e18efdc634ffb7b187 (diff)
downloadcpython-096f1a85f05b478c1e9aabfa23a724d882f65f2a.zip
cpython-096f1a85f05b478c1e9aabfa23a724d882f65f2a.tar.gz
cpython-096f1a85f05b478c1e9aabfa23a724d882f65f2a.tar.bz2
Issue #10911: Add tests on CGI with non-ASCII characters
Patch written by Pierre Quentel
-rw-r--r--Lib/test/test_cgi.py75
-rw-r--r--Misc/NEWS3
2 files changed, 54 insertions, 24 deletions
diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py
index 985de11..d745199 100644
--- a/Lib/test/test_cgi.py
+++ b/Lib/test/test_cgi.py
@@ -197,30 +197,12 @@ class CgiTests(unittest.TestCase):
def test_fieldstorage_multipart(self):
#Test basic FieldStorage multipart parsing
- env = {'REQUEST_METHOD':'POST', 'CONTENT_TYPE':'multipart/form-data; boundary=---------------------------721837373350705526688164684', 'CONTENT_LENGTH':'558'}
- postdata = """-----------------------------721837373350705526688164684
-Content-Disposition: form-data; name="id"
-
-1234
------------------------------721837373350705526688164684
-Content-Disposition: form-data; name="title"
-
-
------------------------------721837373350705526688164684
-Content-Disposition: form-data; name="file"; filename="test.txt"
-Content-Type: text/plain
-
-Testing 123.
-
------------------------------721837373350705526688164684
-Content-Disposition: form-data; name="submit"
-
- Add\x20
------------------------------721837373350705526688164684--
-"""
- encoding = 'ascii'
- fp = BytesIO(postdata.encode(encoding))
- fs = cgi.FieldStorage(fp, environ=env, encoding=encoding)
+ env = {
+ 'REQUEST_METHOD': 'POST',
+ 'CONTENT_TYPE': 'multipart/form-data; boundary={}'.format(BOUNDARY),
+ 'CONTENT_LENGTH': '558'}
+ fp = BytesIO(POSTDATA.encode('latin-1'))
+ fs = cgi.FieldStorage(fp, environ=env, encoding="latin-1")
self.assertEqual(len(fs.list), 4)
expect = [{'name':'id', 'filename':None, 'value':'1234'},
{'name':'title', 'filename':None, 'value':''},
@@ -231,6 +213,21 @@ Content-Disposition: form-data; name="submit"
got = getattr(fs.list[x], k)
self.assertEqual(got, exp)
+ def test_fieldstorage_multipart_non_ascii(self):
+ #Test basic FieldStorage multipart parsing
+ env = {'REQUEST_METHOD':'POST',
+ 'CONTENT_TYPE': 'multipart/form-data; boundary={}'.format(BOUNDARY),
+ 'CONTENT_LENGTH':'558'}
+ for encoding in ['iso-8859-1','utf-8']:
+ fp = BytesIO(POSTDATA_NON_ASCII.encode(encoding))
+ fs = cgi.FieldStorage(fp, environ=env,encoding=encoding)
+ self.assertEqual(len(fs.list), 1)
+ expect = [{'name':'id', 'filename':None, 'value':'\xe7\xf1\x80'}]
+ for x in range(len(fs.list)):
+ for k, exp in expect[x].items():
+ got = getattr(fs.list[x], k)
+ self.assertEqual(got, exp)
+
_qs_result = {
'key1': 'value1',
'key2': ['value2x', 'value2y'],
@@ -346,6 +343,36 @@ this is the content of the fake file
cgi.parse_header('attachment; filename="strange;name";size=123;'),
("attachment", {"filename": "strange;name", "size": "123"}))
+BOUNDARY = "---------------------------721837373350705526688164684"
+
+POSTDATA = """-----------------------------721837373350705526688164684
+Content-Disposition: form-data; name="id"
+
+1234
+-----------------------------721837373350705526688164684
+Content-Disposition: form-data; name="title"
+
+
+-----------------------------721837373350705526688164684
+Content-Disposition: form-data; name="file"; filename="test.txt"
+Content-Type: text/plain
+
+Testing 123.
+
+-----------------------------721837373350705526688164684
+Content-Disposition: form-data; name="submit"
+
+ Add\x20
+-----------------------------721837373350705526688164684--
+"""
+
+POSTDATA_NON_ASCII = """-----------------------------721837373350705526688164684
+Content-Disposition: form-data; name="id"
+
+\xe7\xf1\x80
+-----------------------------721837373350705526688164684
+"""
+
def test_main():
run_unittest(CgiTests)
diff --git a/Misc/NEWS b/Misc/NEWS
index 0e83bbf..a92ac70 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -122,6 +122,9 @@ Build
Tests
-----
+- Issue #10911: Add tests on CGI with non-ASCII characters. Patch written by
+ Pierre Quentel.
+
- Issue #9931: Fix hangs in GUI tests under Windows in certain conditions.
Patch by Hirokazu Yamamoto.