diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2011-06-10 08:39:38 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2011-06-10 08:39:38 +0000 |
| commit | 9e952be26f7d26a90b06a05d3948283943320b7a (patch) | |
| tree | e89623d649669272b593db90d5b0df3abf1d6dcb /tests/regressiontests/requests/tests.py | |
| parent | 046ffa483ed63faae7b31e7e2cf618f88a3312ba (diff) | |
Fixed #16201 -- Ensure that requests with Content-Length=0 don't break the multipart parser. Thanks to albsen for the report and patch
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16353 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/requests/tests.py')
| -rw-r--r-- | tests/regressiontests/requests/tests.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py index 703e387319..91f8b2f805 100644 --- a/tests/regressiontests/requests/tests.py +++ b/tests/regressiontests/requests/tests.py @@ -239,6 +239,27 @@ class RequestsTests(unittest.TestCase): self.assertEqual(request.POST, {u'name': [u'value']}) self.assertRaises(Exception, lambda: request.raw_post_data) + def test_POST_multipart_with_content_length_zero(self): + """ + Multipart POST requests with Content-Length >= 0 are valid and need to be handled. + """ + # According to: + # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13 + # Every request.POST with Content-Length >= 0 is a valid request, + # this test ensures that we handle Content-Length == 0. + payload = "\r\n".join([ + '--boundary', + 'Content-Disposition: form-data; name="name"', + '', + 'value', + '--boundary--' + '']) + request = WSGIRequest({'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': 'multipart/form-data; boundary=boundary', + 'CONTENT_LENGTH': 0, + 'wsgi.input': StringIO(payload)}) + self.assertEqual(request.POST, {}) + def test_read_by_lines(self): request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')}) self.assertEqual(list(request), ['name=value']) |
