Skip to content

Commit

Permalink
1.7.1dev: merge [17831:17832] from 1.6-stable (fix for #13761,13762)
Browse files Browse the repository at this point in the history
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@17833 af82e41b-90c4-0310-8c96-b1721e28e2e2
  • Loading branch information
jomae committed Jun 25, 2024
2 parents 3a8724c + 8b78522 commit 5d74101
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion 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 Expand Up @@ -1028,7 +1030,7 @@ def _send(self, content, content_type='text/html', status=200,
self.send_header('Cache-Control', 'must-revalidate')
self.send_header('Expires', 'Fri, 01 Jan 1999 00:00:00 GMT')
self.send_header('Content-Type', content_type + ';charset=utf-8')
if isinstance(content, str):
if isinstance(content, bytes):
self.send_header('Content-Length', len(content))
self.end_headers(exc_info)

Expand Down
15 changes: 15 additions & 0 deletions trac/web/tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,23 @@ 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'))
with self.assertRaises(RequestDone):
req.send(b'\xef\xbb\xbf')
self.assertEqual('3', req.headers_sent.get('Content-Length'))

def test_send_unicode(self):
req = _make_req(_make_environ(method='GET'))
with self.assertRaises(ValueError):
req.send(u'\ufeff')

def test_send_iterable(self):
def iterable():
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 5d74101

Please sign in to comment.