mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
bytes data. Patch by Jonas Wagner.
This commit is contained in:
parent
3d9e972270
commit
6b102f251f
3 changed files with 32 additions and 10 deletions
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue