mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[1.10.x] Fixed #26644 -- Allowed wrapping NamedTemporaryFile with File.
914c72be2aintroduced a regression that causes saving a NamedTemporaryFile in a FileField to raise a SuspiciousFileOperation. To remedy this, if a File has an absolute path as a filename, use only the basename as the filename. Backport of1b407050ddfrom master
This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							84737135f6
						
					
				
				
					commit
					c37f9253a6
				
			| @@ -10,6 +10,7 @@ import threading | ||||
| import time | ||||
| import unittest | ||||
| from datetime import datetime, timedelta | ||||
| from tempfile import NamedTemporaryFile | ||||
|  | ||||
| from django.core.cache import cache | ||||
| from django.core.exceptions import SuspiciousFileOperation, SuspiciousOperation | ||||
| @@ -871,6 +872,13 @@ class FileFieldStorageTests(TestCase): | ||||
|         with temp_storage.open('tests/stringio') as f: | ||||
|             self.assertEqual(f.read(), b'content') | ||||
|  | ||||
|     def test_save_temporary_file(self): | ||||
|         storage = Storage() | ||||
|         with NamedTemporaryFile() as f: | ||||
|             f.write(b'content') | ||||
|             storage.normal = File(f) | ||||
|             storage.save()  # no crash | ||||
|  | ||||
|  | ||||
| # Tests for a race condition on file saving (#4948). | ||||
| # This is written in such a way that it'll always pass on platforms | ||||
|   | ||||
		Reference in New Issue
	
	Block a user