Ticket #15018: test_and_fix_for_ticket_15018.diff

File test_and_fix_for_ticket_15018.diff, 1.5 KB (added by aaugustin, 4 years ago)
  • django/core/handlers/wsgi.py

     
    9696        return result
    9797
    9898    def readline(self, size=None):
    99         while '\n' not in self.buffer or \
    100               (size is not None and len(self.buffer) < size):
     99        while '\n' not in self.buffer and \
     100              (size is None or len(self.buffer) < size):
    101101            if size:
     102                # since size is not None here, len(self.buffer) < size
    102103                chunk = self._read_limited(size - len(self.buffer))
    103104            else:
    104105                chunk = self._read_limited()
  • tests/regressiontests/requests/tests.py

     
    129129        # Read everything else.
    130130        self.assertEqual(stream.readline(), 'ijkl')
    131131
     132    def test_limited_stream_ticket_15018(self):
     133        stream = LimitedStream(StringIO('\nabc'), 3)
     134        self.assertEqual(stream.readline(3), '\n')
     135        self.assertEqual(stream.readline(1), 'a')
     136        self.assertEqual(stream.readline(1), 'b')
     137        # Hit stream limit
     138        self.assertEqual(stream.readline(1), '')
     139
    132140    def test_stream(self):
    133141        request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')})
    134142        self.assertEqual(request.read(), 'name=value')
Back to Top