Edgewall Software
Modify

Opened 6 months ago

Closed 6 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:

Request.write raises a ValueError for an empty str instance now.

API Changes:
Internal Changes:

Description (last modified by Jun Omae)

>>> 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):  
    982982        there are multiple calls to `write`, to the cumulative length
    983983        of the *data* arguments.
    984984        """
     985        if isinstance(data, str):
     986            raise ValueError("Can't send str content")
    985987        if not self._write:
    986988            self.end_headers()
    987989        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\  
    440440        # anyway we're not supposed to send unicode, so we get a ValueError
    441441        with self.assertRaises(ValueError):
    442442            req.write('Föö')
     443        with self.assertRaises(ValueError):
     444            req.write('')
    443445        with self.assertRaises(ValueError):
    444446            req.write((b'F', 'öo'))
     447        with self.assertRaises(ValueError):
     448            req.write(('Föo'.encode('utf-8'), ''))
    445449
    446450    def test_send_iterable(self):
    447451        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):  
    9090            def process_request(self, req):
    9191                self.calls += 1
    9292                req.authname
    93                 req.send('')
     93                req.send(b'')
    9494
    9595        cls.authenticators['success1'] = SuccessfulAuthenticator1
    9696        cls.authenticators['success2'] = SuccessfulAuthenticator2

Attachments (0)

Change History (1)

comment:1 by Jun Omae, 6 months ago

Description: modified (diff)
Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Fixed in [17832] and merged in [17833].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.