Do not include uploads in request.POST (#4407)

This commit is contained in:
Tom Christie 2016-08-15 16:53:17 +01:00 committed by GitHub
parent 785b206b81
commit 101fd29039
2 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -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.