Skip to content

Commit

Permalink
Fix HTTPResponse.setBody when the publisher returns a tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Oct 2, 2018
1 parent 4e3e995 commit 003325c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Bugfixes
when reading request bodies not encoded as application/x-www-form-urlencoded
or multipart/form-data.

- Fix `HTTPResponse.setBody` when the published object returns a tuple.


4.0b5 (2018-05-18)
------------------
Expand Down
2 changes: 1 addition & 1 deletion src/ZPublisher/HTTPResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def setBody(self, body, title='', is_error=False, lock=None):
else:
try:
body = bytes(body)
except UnicodeError:
except (TypeError, UnicodeError):
body = self._encode_unicode(text_type(body))

# At this point body is always binary
Expand Down
4 changes: 4 additions & 0 deletions src/ZPublisher/tests/testHTTPResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,10 @@ def test_setBody_w_bogus_pseudo_HTML(self):
response = self._makeOne()
self.assertRaises(NotFound, response.setBody, BOGUS)

def test_setBody_tuple(self):
response = self._makeOne()
self.assertEqual(b"('a',)", response.setBody(('a',)))

def test_setBody_calls_insertBase(self):
response = self._makeOne()
lamb = {}
Expand Down

0 comments on commit 003325c

Please sign in to comment.