Modify ↓
Opened 5 months ago
Closed 5 months ago
#13762 closed defect (fixed)
Request.write with an empty str instance doesn't raise ValueError
Reported by: | Jun Omae | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Milestone: | 1.6.1 |
Component: | general | Version: | 1.6 |
Severity: | minor | Keywords: | |
Cc: | Branch: | ||
Release Notes: |
|
||
API Changes: | |||
Internal Changes: |
Description (last modified by )
>>> from trac.test import EnvironmentStub, MockRequest >>> env = EnvironmentStub() >>> req = MockRequest(env) >>> req.send(u'unicode contents') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/jun66j5/src/tracdev/git/trac/web/api.py", line 900, in send self._send(content, content_type, status) File "/home/jun66j5/src/tracdev/git/trac/web/api.py", line 1036, in _send self.write(content) File "/home/jun66j5/src/tracdev/git/trac/web/api.py", line 996, in write raise ValueError("Can't send str content") ValueError: Can't send str content >>> req.send(u'') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/jun66j5/src/tracdev/git/trac/web/api.py", line 900, in send self._send(content, content_type, status) File "/home/jun66j5/src/tracdev/git/trac/web/api.py", line 1037, in _send raise RequestDone trac.web.api.RequestDone
Patch:
-
trac/web/api.py
diff --git a/trac/web/api.py b/trac/web/api.py index 383db0a06..7f8b59bdc 100644
a b class Request(object): 982 982 there are multiple calls to `write`, to the cumulative length 983 983 of the *data* arguments. 984 984 """ 985 if isinstance(data, str): 986 raise ValueError("Can't send str content") 985 987 if not self._write: 986 988 self.end_headers() 987 989 try: -
trac/web/tests/api.py
diff --git a/trac/web/tests/api.py b/trac/web/tests/api.py index 01010e120..bd14c1010 100644
a b new\r\n\ 440 440 # anyway we're not supposed to send unicode, so we get a ValueError 441 441 with self.assertRaises(ValueError): 442 442 req.write('Föö') 443 with self.assertRaises(ValueError): 444 req.write('') 443 445 with self.assertRaises(ValueError): 444 446 req.write((b'F', 'öo')) 447 with self.assertRaises(ValueError): 448 req.write(('Föo'.encode('utf-8'), '')) 445 449 446 450 def test_send_iterable(self): 447 451 def iterable(): -
trac/web/tests/main.py
diff --git a/trac/web/tests/main.py b/trac/web/tests/main.py index 1dfdd8164..d1cfbb338 100644
a b class AuthenticateTestCase(unittest.TestCase): 90 90 def process_request(self, req): 91 91 self.calls += 1 92 92 req.authname 93 req.send( '')93 req.send(b'') 94 94 95 95 cls.authenticators['success1'] = SuccessfulAuthenticator1 96 96 cls.authenticators['success2'] = SuccessfulAuthenticator2
Attachments (0)
Note:
See TracTickets
for help on using tickets.
Fixed in [17832] and merged in [17833].