mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Refs #17235 -- Made MultiPartParser leave request.POST immutable.
This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							183f501540
						
					
				
				
					commit
					4a246a02bd
				
			| @@ -1785,7 +1785,7 @@ class ModelAdmin(BaseModelAdmin): | ||||
|             } | ||||
|             if request.method == 'POST': | ||||
|                 formset_params.update({ | ||||
|                     'data': request.POST, | ||||
|                     'data': request.POST.copy(), | ||||
|                     'files': request.FILES, | ||||
|                     'save_as_new': '_saveasnew' in request.POST | ||||
|                 }) | ||||
|   | ||||
| @@ -205,6 +205,7 @@ class UserAdmin(admin.ModelAdmin): | ||||
|         # * The user has pressed the 'Save and add another' button | ||||
|         # * We are adding a user in a popup | ||||
|         if '_addanother' not in request.POST and IS_POPUP_VAR not in request.POST: | ||||
|             request.POST = request.POST.copy() | ||||
|             request.POST['_continue'] = 1 | ||||
|         return super(UserAdmin, self).response_add(request, obj, | ||||
|                                                    post_url_continue) | ||||
|   | ||||
| @@ -289,6 +289,7 @@ class MultiPartParser(object): | ||||
|             if retval: | ||||
|                 break | ||||
|  | ||||
|         self._post._mutable = False | ||||
|         return self._post, self._files | ||||
|  | ||||
|     def handle_file_complete(self, old_field_name, counters): | ||||
|   | ||||
| @@ -634,6 +634,10 @@ Miscellaneous | ||||
|  | ||||
| * The undocumented ``django.utils.functional.lazy_property`` is removed. | ||||
|  | ||||
| * For consistency with non-multipart requests, ``MultiPartParser.parse()`` now | ||||
|   leaves ``request.POST`` immutable. If you're modifying that ``QueryDict``, | ||||
|   you must now first copy it, e.g. ``request.POST.copy()``. | ||||
|  | ||||
| .. _deprecated-features-1.11: | ||||
|  | ||||
| Features deprecated in 1.11 | ||||
|   | ||||
| @@ -533,6 +533,25 @@ class RequestsTests(SimpleTestCase): | ||||
|         self.assertEqual(request.read(13), b'--boundary\r\nC') | ||||
|         self.assertEqual(request.POST, {'name': ['value']}) | ||||
|  | ||||
|     def test_POST_immutable_for_mutipart(self): | ||||
|         """ | ||||
|         MultiPartParser.parse() leaves request.POST immutable. | ||||
|         """ | ||||
|         payload = FakePayload("\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': len(payload), | ||||
|             'wsgi.input': payload, | ||||
|         }) | ||||
|         self.assertFalse(request.POST._mutable) | ||||
|  | ||||
|     def test_POST_connection_error(self): | ||||
|         """ | ||||
|         If wsgi.input.read() raises an exception while trying to read() the | ||||
|   | ||||
		Reference in New Issue
	
	Block a user