Skip to content

Commit

Permalink
Fix empty file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Jul 10, 2019
1 parent 2dade9a commit 4c26b15
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/zope/publisher/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def _decode(self, text):
envadapter = IUserPreferredCharsets(self)
self.charsets = envadapter.getPreferredCharsets() or ['utf-8']
self.charsets = [c for c in self.charsets if c != '*']
if not PYTHON2:
if not PYTHON2 and not isinstance(text, bytes):
if self.charsets and self.charsets[0] == 'iso-8859-1':
# optimization: we are trying to decode something
# cgi.FieldStorage already decoded for us, let's just return it
Expand Down
17 changes: 17 additions & 0 deletions src/zope/publisher/tests/test_browserrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
from zope.publisher.tests.basetestiapplicationrequest \
import BaseTestIApplicationRequest


EMPTY_FILE_BODY = b"""-----------------------------1
Content-Disposition: form-data; name="upload"; filename=""
Content-Type: application/octet-stream
-----------------------------1--
"""

LARGE_FILE_BODY = b''.join([b"""-----------------------------1
Content-Disposition: form-data; name="upload"; filename="test"
Content-Type: text/plain
Expand Down Expand Up @@ -228,6 +236,15 @@ def testFileUploadPost(self):
# Test that we can actually read the file data
self.assertEqual(request.form['upload'].read(), b'Some data')

def testEmptyFilePost(self):
extra = {'REQUEST_METHOD':'POST',
'PATH_INFO': u"/",
'CONTENT_TYPE': 'multipart/form-data;\
boundary=---------------------------1'}

request = self._createRequest(extra, body=EMPTY_FILE_BODY)
request.processInputs()

def testLargePostValue(self):
extra = {'REQUEST_METHOD':'POST',
'PATH_INFO': u"/",
Expand Down

0 comments on commit 4c26b15

Please sign in to comment.