Skip to content

Commit

Permalink
1.6.1dev: Request.write raises a ValueError for an empty str in…
Browse files Browse the repository at this point in the history
…stance now (closes #13762)

git-svn-id: http://trac.edgewall.org/intertrac/log:/branches/1.6-stable@17832 af82e41b-90c4-0310-8c96-b1721e28e2e2
  • Loading branch information
jomae committed Jun 25, 2024
1 parent 9a91398 commit 8b78522
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions trac/web/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,8 @@ def write(self, data):
there are multiple calls to `write`, to the cumulative length
of the *data* arguments.
"""
if isinstance(data, str):
raise ValueError("Can't send str content")
if not self._write:
self.end_headers()
try:
Expand Down
4 changes: 4 additions & 0 deletions trac/web/tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,12 @@ def test_write_unicode(self):
# anyway we're not supposed to send unicode, so we get a ValueError
with self.assertRaises(ValueError):
req.write('Föö')
with self.assertRaises(ValueError):
req.write('')
with self.assertRaises(ValueError):
req.write((b'F', 'öo'))
with self.assertRaises(ValueError):
req.write(('Föo'.encode('utf-8'), ''))

def test_send_bytes(self):
req = _make_req(_make_environ(method='GET'))
Expand Down
2 changes: 1 addition & 1 deletion trac/web/tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def match_request(self, req):
def process_request(self, req):
self.calls += 1
req.authname
req.send('')
req.send(b'')

cls.authenticators['success1'] = SuccessfulAuthenticator1
cls.authenticators['success2'] = SuccessfulAuthenticator2
Expand Down

0 comments on commit 8b78522

Please sign in to comment.