1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #26644 -- Allowed wrapping NamedTemporaryFile with File.

914c72be2a introduced 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.
This commit is contained in:
Hugo Osvaldo Barrera
2016-05-27 14:54:26 -03:00
committed by Tim Graham
parent fa654da613
commit 1b407050dd
3 changed files with 18 additions and 0 deletions

View File

@@ -18,6 +18,10 @@ class File(FileProxyMixin):
self.file = file
if name is None:
name = getattr(file, 'name', None)
# Use only the basename from a file's name if it's an absolute path,
# e.g. from NamedTemporaryFile.
if isinstance(name, six.string_types) and os.path.isabs(name):
name = os.path.basename(name)
self.name = name
if hasattr(file, 'mode'):
self.mode = file.mode