diff options
author | Donald Stufft <donald@stufft.io> | 2015-03-29 16:43:23 -0400 |
---|---|---|
committer | Donald Stufft <donald@stufft.io> | 2015-03-29 16:43:23 -0400 |
commit | d90f8d10e088657593fa753ecacab95845d378aa (patch) | |
tree | 826e1017d337826a9b6818539d954ca4c1332c2b /Lib/test/test_cgi.py | |
parent | 1058cda38f1b409c4d52eef236f4915df592a112 (diff) | |
download | cpython-git-d90f8d10e088657593fa753ecacab95845d378aa.tar.gz |
Closes #23801 - Ignore entire preamble to multipart in cgi.FieldStorage
Diffstat (limited to 'Lib/test/test_cgi.py')
-rw-r--r-- | Lib/test/test_cgi.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py index 1127dd12e6..d2c326bfb2 100644 --- a/Lib/test/test_cgi.py +++ b/Lib/test/test_cgi.py @@ -248,6 +248,25 @@ class CgiTests(unittest.TestCase): got = getattr(fs.list[x], k) self.assertEqual(got, exp) + def test_fieldstorage_multipart_leading_whitespace(self): + env = { + 'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'multipart/form-data; boundary={}'.format(BOUNDARY), + 'CONTENT_LENGTH': '560'} + # Add some leading whitespace to our post data that will cause the + # first line to not be the innerboundary. + fp = BytesIO(b"\r\n" + 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':''}, + {'name':'file', 'filename':'test.txt', 'value':b'Testing 123.\n'}, + {'name':'submit', 'filename':None, 'value':' Add '}] + for x in range(len(fs.list)): + for k, exp in expect[x].items(): + 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', |