mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 11:33:59 +03:00
Do not include uploads in request.POST (#4407)
This commit is contained in:
parent
785b206b81
commit
101fd29039
|
@ -373,7 +373,7 @@ class Request(object):
|
||||||
if not _hasattr(self, '_data'):
|
if not _hasattr(self, '_data'):
|
||||||
self._load_data_and_files()
|
self._load_data_and_files()
|
||||||
if is_form_media_type(self.content_type):
|
if is_form_media_type(self.content_type):
|
||||||
return self.data
|
return self._data
|
||||||
return QueryDict('', encoding=self._request._encoding)
|
return QueryDict('', encoding=self._request._encoding)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -7,6 +7,7 @@ from django.conf.urls import url
|
||||||
from django.contrib.auth import authenticate, login, logout
|
from django.contrib.auth import authenticate, login, logout
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.sessions.middleware import SessionMiddleware
|
from django.contrib.sessions.middleware import SessionMiddleware
|
||||||
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
||||||
|
@ -78,6 +79,16 @@ class TestContentParsing(TestCase):
|
||||||
request.parsers = (FormParser(), MultiPartParser())
|
request.parsers = (FormParser(), MultiPartParser())
|
||||||
self.assertEqual(list(request.POST.items()), list(data.items()))
|
self.assertEqual(list(request.POST.items()), list(data.items()))
|
||||||
|
|
||||||
|
def test_request_POST_with_files(self):
|
||||||
|
"""
|
||||||
|
Ensure request.POST returns no content for POST request with file content.
|
||||||
|
"""
|
||||||
|
upload = SimpleUploadedFile("file.txt", b"file_content")
|
||||||
|
request = Request(factory.post('/', {'upload': upload}))
|
||||||
|
request.parsers = (FormParser(), MultiPartParser())
|
||||||
|
self.assertEqual(list(request.POST.keys()), [])
|
||||||
|
self.assertEqual(list(request.FILES.keys()), ['upload'])
|
||||||
|
|
||||||
def test_standard_behaviour_determines_form_content_PUT(self):
|
def test_standard_behaviour_determines_form_content_PUT(self):
|
||||||
"""
|
"""
|
||||||
Ensure request.data returns content for PUT request with form content.
|
Ensure request.data returns content for PUT request with form content.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user