diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2013-01-23 10:50:15 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2013-01-23 10:50:15 (GMT) |
commit | 6b102f251f086feb058ed9aac8072bbafe362372 (patch) | |
tree | 35ec3908e0a2bcf9eb521fd39fc023d51dd1f04f /Lib/test/test_cgi.py | |
parent | 3d9e972270270e1498712065a17ec3a589ae8986 (diff) | |
download | cpython-6b102f251f086feb058ed9aac8072bbafe362372.zip cpython-6b102f251f086feb058ed9aac8072bbafe362372.tar.gz cpython-6b102f251f086feb058ed9aac8072bbafe362372.tar.bz2 |
Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
bytes data. Patch by Jonas Wagner.
Diffstat (limited to 'Lib/test/test_cgi.py')
-rw-r--r-- | Lib/test/test_cgi.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py index 3031fb3..07e760b 100644 --- a/Lib/test/test_cgi.py +++ b/Lib/test/test_cgi.py @@ -4,6 +4,7 @@ import os import sys import tempfile import unittest +from collections import namedtuple from io import StringIO, BytesIO class HackedSysModule: @@ -118,6 +119,23 @@ def gen_result(data, environ): class CgiTests(unittest.TestCase): + def test_parse_multipart(self): + fp = BytesIO(POSTDATA.encode('latin1')) + env = {'boundary': BOUNDARY.encode('latin1'), + 'CONTENT-LENGTH': '558'} + result = cgi.parse_multipart(fp, env) + expected = {'submit': [b' Add '], 'id': [b'1234'], + 'file': [b'Testing 123.\n'], 'title': [b'']} + self.assertEqual(result, expected) + + def test_fieldstorage_properties(self): + fs = cgi.FieldStorage() + self.assertFalse(fs) + self.assertIn("FieldStorage", repr(fs)) + self.assertEqual(list(fs), list(fs.keys())) + fs.list.append(namedtuple('MockFieldStorage', 'name')('fieldvalue')) + self.assertTrue(fs) + def test_escape(self): self.assertEqual("test & string", cgi.escape("test & string")) self.assertEqual("<test string>", cgi.escape("<test string>")) @@ -151,7 +169,8 @@ class CgiTests(unittest.TestCase): def test_log(self): cgi.log("Testing") - + cgi.logfile = "fail/" + cgi.initlog("%s", "Testing initlog") cgi.logfp = StringIO() cgi.initlog("%s", "Testing initlog 1") cgi.log("%s", "Testing log 2") |