summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Sutherland <brian@vanguardistas.net>2017-03-01 17:32:00 +0100
committerBrian Sutherland <brian@vanguardistas.net>2017-03-02 13:33:15 +0100
commitd8ae1f2b6d4077e3631cb3518067f7a3ade317a6 (patch)
tree369e8bb4d1168fe9520dad97483cd00f3cf5eac0 /src
parent0565a81faf06b48e1192e30d20603e979ff53d12 (diff)
downloadzope-publisher-d8ae1f2b6d4077e3631cb3518067f7a3ade317a6.tar.gz
Fix POST with large values on Python 3
Diffstat (limited to 'src')
-rw-r--r--src/zope/publisher/browser.py6
-rw-r--r--src/zope/publisher/tests/test_browserrequest.py16
2 files changed, 21 insertions, 1 deletions
diff --git a/src/zope/publisher/browser.py b/src/zope/publisher/browser.py
index 710793c..f9e11f8 100644
--- a/src/zope/publisher/browser.py
+++ b/src/zope/publisher/browser.py
@@ -613,7 +613,11 @@ class BrowserRequest(HTTPRequest):
class ZopeFieldStorage(FieldStorage):
def make_file(self, binary=None):
- return tempfile.NamedTemporaryFile('w+b')
+ if PYTHON2 or self._binary_file:
+ return tempfile.NamedTemporaryFile("w+b")
+ else:
+ return tempfile.NamedTemporaryFile("w+",
+ encoding=self.encoding, newline='\n')
class FileUpload(object):
diff --git a/src/zope/publisher/tests/test_browserrequest.py b/src/zope/publisher/tests/test_browserrequest.py
index 767bebb7..dd95094 100644
--- a/src/zope/publisher/tests/test_browserrequest.py
+++ b/src/zope/publisher/tests/test_browserrequest.py
@@ -48,6 +48,13 @@ Here comes some text! """, (b'test'*1000), b"""
-----------------------------1--
"""])
+LARGE_POSTED_VALUE = b''.join([b"""-----------------------------1
+Content-Disposition: form-data; name="upload"
+
+Here comes some text! """, (b'test'*1000), b"""
+-----------------------------1--
+"""])
+
IE_FILE_BODY = b"""-----------------------------1
Content-Disposition: form-data; name="upload"; filename="C:\\Windows\\notepad.exe"
Content-Type: text/plain
@@ -220,6 +227,15 @@ class BrowserTests(HTTPTests):
# Test that we can actually read the file data
self.assertEqual(request.form['upload'].read(), b'Some data')
+ def testLargePostValue(self):
+ extra = {'REQUEST_METHOD':'POST',
+ 'PATH_INFO': _u("/"),
+ 'CONTENT_TYPE': 'multipart/form-data;\
+ boundary=---------------------------1'}
+
+ request = self._createRequest(extra, body=LARGE_POSTED_VALUE)
+ request.processInputs()
+
def testDefault2(self):
extra = {'PATH_INFO': '/folder/item2/view'}
request = self._createRequest(extra)