Code

Ticket #15018: test_and_fix_for_ticket_15018.diff

File test_and_fix_for_ticket_15018.diff, 1.5 KB (added by aaugustin, 3 years ago)
Line 
1Index: django/core/handlers/wsgi.py
2===================================================================
3--- django/core/handlers/wsgi.py        (revision 15216)
4+++ django/core/handlers/wsgi.py        (working copy)
5@@ -96,9 +96,10 @@
6         return result
7 
8     def readline(self, size=None):
9-        while '\n' not in self.buffer or \
10-              (size is not None and len(self.buffer) < size):
11+        while '\n' not in self.buffer and \
12+              (size is None or len(self.buffer) < size):
13             if size:
14+                # since size is not None here, len(self.buffer) < size
15                 chunk = self._read_limited(size - len(self.buffer))
16             else:
17                 chunk = self._read_limited()
18Index: tests/regressiontests/requests/tests.py
19===================================================================
20--- tests/regressiontests/requests/tests.py     (revision 15216)
21+++ tests/regressiontests/requests/tests.py     (working copy)
22@@ -129,6 +129,14 @@
23         # Read everything else.
24         self.assertEqual(stream.readline(), 'ijkl')
25 
26+    def test_limited_stream_ticket_15018(self):
27+        stream = LimitedStream(StringIO('\nabc'), 3)
28+        self.assertEqual(stream.readline(3), '\n')
29+        self.assertEqual(stream.readline(1), 'a')
30+        self.assertEqual(stream.readline(1), 'b')
31+        # Hit stream limit
32+        self.assertEqual(stream.readline(1), '')
33+
34     def test_stream(self):
35         request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')})
36         self.assertEqual(request.read(), 'name=value')