Skip to content

Commit 600aa66

Browse files
committed
Fixed #11030: Reverted a change that assumed the file system encoding was utf8, and changed a test to demonstrate how that assumption corrupted uploaded non-ASCII file names on systems that don't use utf8 as their file system encoding (Windows for one, specifically). Thanks for the report to vrehak.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12661 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 125c748 commit 600aa66

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

django/core/files/storage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation
88
from django.core.files import locks, File
99
from django.core.files.move import file_move_safe
10-
from django.utils.encoding import force_unicode, smart_str
10+
from django.utils.encoding import force_unicode
1111
from django.utils.functional import LazyObject
1212
from django.utils.importlib import import_module
1313
from django.utils.text import get_valid_filename
@@ -210,7 +210,7 @@ def path(self, name):
210210
path = safe_join(self.location, name)
211211
except ValueError:
212212
raise SuspiciousOperation("Attempted access to '%s' denied." % name)
213-
return smart_str(os.path.normpath(path))
213+
return os.path.normpath(path)
214214

215215
def size(self, name):
216216
return os.path.getsize(self.path(name))

tests/regressiontests/file_uploads/views.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from django.core.files.uploadedfile import UploadedFile
33
from django.http import HttpResponse, HttpResponseServerError
44
from django.utils import simplejson
5-
from models import FileModel
5+
from models import FileModel, UPLOAD_TO
66
from uploadhandler import QuotaUploadHandler, ErroringUploadHandler
77
from django.utils.hashcompat import sha_constructor
88
from tests import UNICODE_FILENAME
@@ -18,7 +18,7 @@ def file_upload_view(request):
1818
# If a file is posted, the dummy client should only post the file name,
1919
# not the full path.
2020
if os.path.dirname(form_data['file_field'].name) != '':
21-
return HttpResponseServerError()
21+
return HttpResponseServerError()
2222
return HttpResponse('')
2323
else:
2424
return HttpResponseServerError()
@@ -62,7 +62,8 @@ def file_upload_unicode_name(request):
6262
# through file save.
6363
uni_named_file = request.FILES['file_unicode']
6464
obj = FileModel.objects.create(testfile=uni_named_file)
65-
if not obj.testfile.name.endswith(uni_named_file.name):
65+
full_name = u'%s/%s' % (UPLOAD_TO, uni_named_file.name)
66+
if not os.path.exists(full_name):
6667
response = HttpResponseServerError()
6768

6869
# Cleanup the object with its exotic file name immediately.
@@ -82,14 +83,14 @@ def file_upload_echo(request):
8283
"""
8384
r = dict([(k, f.name) for k, f in request.FILES.items()])
8485
return HttpResponse(simplejson.dumps(r))
85-
86+
8687
def file_upload_quota(request):
8788
"""
8889
Dynamically add in an upload handler.
8990
"""
9091
request.upload_handlers.insert(0, QuotaUploadHandler())
9192
return file_upload_echo(request)
92-
93+
9394
def file_upload_quota_broken(request):
9495
"""
9596
You can't change handlers after reading FILES; this view shouldn't work.

0 commit comments

Comments
 (0)