Ticket #16201: multipartparser_content_length_0.diff
File multipartparser_content_length_0.diff, 2.5 KB (added by , 13 years ago) |
---|
-
django/http/multipartparser.py
75 75 # For now set it to 0; we'll try again later on down. 76 76 content_length = 0 77 77 78 if content_length < =0:78 if content_length < 0: 79 79 # This means we shouldn't continue...raise an error. 80 80 raise MultiPartParserError("Invalid content length: %r" % content_length) 81 81 … … 105 105 encoding = self._encoding 106 106 handlers = self._upload_handlers 107 107 108 # HTTP spec says that Content-Length >= 0 is valid 109 # handling content-length == 0 before continuing 110 if self._content_length == 0: 111 return QueryDict(MultiValueDict(), encoding=self._encoding), MultiValueDict() 112 108 113 limited_input_data = LimitBytes(self._input_data, self._content_length) 109 114 110 115 # See if the handler will want to take care of the parsing. -
tests/regressiontests/requests/tests.py
200 200 self.assertEqual(request.POST, {u'name': [u'value']}) 201 201 self.assertRaises(Exception, lambda: request.raw_post_data) 202 202 203 def test_POST_multipart_with_content_length_zero(self): 204 """ 205 Multipart POST requests with Content-Length >= 0 are valid and need to be handled. 206 """ 207 # According to: 208 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13 209 # Every request.POST with Content-Length >= 0 is a valid request, 210 # this test ensures that we handle Content-Length == 0. 211 payload = "\r\n".join([ 212 '--boundary', 213 'Content-Disposition: form-data; name="name"', 214 '', 215 'value', 216 '--boundary--' 217 '']) 218 request = WSGIRequest({'REQUEST_METHOD': 'POST', 219 'CONTENT_TYPE': 'multipart/form-data; boundary=boundary', 220 'CONTENT_LENGTH': 0, 221 'wsgi.input': StringIO(payload)}) 222 self.assertEqual(request.POST, {}) 223 203 224 def test_read_by_lines(self): 204 225 request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')}) 205 226 self.assertEqual(list(request), ['name=value'])