mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
merge from 3.2
Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and bytes data. Patch by Jonas Wagner.
This commit is contained in:
commit
c1a7c565aa
3 changed files with 30 additions and 9 deletions
|
@ -5,6 +5,7 @@ import sys
|
|||
import tempfile
|
||||
import unittest
|
||||
import warnings
|
||||
from collections import namedtuple
|
||||
from io import StringIO, BytesIO
|
||||
|
||||
class HackedSysModule:
|
||||
|
@ -119,6 +120,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):
|
||||
# cgi.escape() is deprecated.
|
||||
with warnings.catch_warnings():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue