Fixed #30227 -- Fixed crash on request without boundary in Content-Type.
This commit is contained in:
parent
8a2ec55b18
commit
2ed2acf872
|
@ -70,7 +70,7 @@ class MultiPartParser:
|
||||||
ctypes, opts = parse_header(content_type.encode('ascii'))
|
ctypes, opts = parse_header(content_type.encode('ascii'))
|
||||||
boundary = opts.get('boundary')
|
boundary = opts.get('boundary')
|
||||||
if not boundary or not cgi.valid_boundary(boundary):
|
if not boundary or not cgi.valid_boundary(boundary):
|
||||||
raise MultiPartParserError('Invalid boundary in multipart: %s' % boundary.decode())
|
raise MultiPartParserError('Invalid boundary in multipart: %s' % force_str(boundary))
|
||||||
|
|
||||||
# Content-Length should contain the length of the body we are about
|
# Content-Length should contain the length of the body we are about
|
||||||
# to receive.
|
# to receive.
|
||||||
|
|
|
@ -5,6 +5,7 @@ from urllib.parse import urlencode
|
||||||
from django.core.exceptions import DisallowedHost
|
from django.core.exceptions import DisallowedHost
|
||||||
from django.core.handlers.wsgi import LimitedStream, WSGIRequest
|
from django.core.handlers.wsgi import LimitedStream, WSGIRequest
|
||||||
from django.http import HttpRequest, RawPostDataException, UnreadablePostError
|
from django.http import HttpRequest, RawPostDataException, UnreadablePostError
|
||||||
|
from django.http.multipartparser import MultiPartParserError
|
||||||
from django.http.request import HttpHeaders, split_domain_port
|
from django.http.request import HttpHeaders, split_domain_port
|
||||||
from django.test import RequestFactory, SimpleTestCase, override_settings
|
from django.test import RequestFactory, SimpleTestCase, override_settings
|
||||||
from django.test.client import FakePayload
|
from django.test.client import FakePayload
|
||||||
|
@ -476,6 +477,16 @@ class RequestsTests(SimpleTestCase):
|
||||||
})
|
})
|
||||||
self.assertFalse(request.POST._mutable)
|
self.assertFalse(request.POST._mutable)
|
||||||
|
|
||||||
|
def test_multipart_without_boundary(self):
|
||||||
|
request = WSGIRequest({
|
||||||
|
'REQUEST_METHOD': 'POST',
|
||||||
|
'CONTENT_TYPE': 'multipart/form-data;',
|
||||||
|
'CONTENT_LENGTH': 0,
|
||||||
|
'wsgi.input': FakePayload(),
|
||||||
|
})
|
||||||
|
with self.assertRaisesMessage(MultiPartParserError, 'Invalid boundary in multipart: None'):
|
||||||
|
request.POST
|
||||||
|
|
||||||
def test_POST_connection_error(self):
|
def test_POST_connection_error(self):
|
||||||
"""
|
"""
|
||||||
If wsgi.input.read() raises an exception while trying to read() the
|
If wsgi.input.read() raises an exception while trying to read() the
|
||||||
|
|
Loading…
Reference in New Issue