Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #12898: 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.

r12661 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12662 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c6e662cd6e84203ca0a5328035d72c6c83f9bae9 1 parent b50b3cf
Karen Tracey authored March 02, 2010
4  django/core/files/storage.py
@@ -6,7 +6,7 @@
6 6
 from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation
7 7
 from django.core.files import locks, File
8 8
 from django.core.files.move import file_move_safe
9  
-from django.utils.encoding import force_unicode, smart_str
  9
+from django.utils.encoding import force_unicode
10 10
 from django.utils.functional import LazyObject
11 11
 from django.utils.importlib import import_module
12 12
 from django.utils.text import get_valid_filename
@@ -212,7 +212,7 @@ def path(self, name):
212 212
             path = safe_join(self.location, name)
213 213
         except ValueError:
214 214
             raise SuspiciousOperation("Attempted access to '%s' denied." % name)
215  
-        return smart_str(os.path.normpath(path))
  215
+        return os.path.normpath(path)
216 216
 
217 217
     def size(self, name):
218 218
         return os.path.getsize(self.path(name))
11  tests/regressiontests/file_uploads/views.py
@@ -2,7 +2,7 @@
2 2
 from django.core.files.uploadedfile import UploadedFile
3 3
 from django.http import HttpResponse, HttpResponseServerError
4 4
 from django.utils import simplejson
5  
-from models import FileModel
  5
+from models import FileModel, UPLOAD_TO
6 6
 from uploadhandler import QuotaUploadHandler, ErroringUploadHandler
7 7
 from django.utils.hashcompat import sha_constructor
8 8
 from tests import UNICODE_FILENAME
@@ -18,7 +18,7 @@ def file_upload_view(request):
18 18
         # If a file is posted, the dummy client should only post the file name,
19 19
         # not the full path.
20 20
         if os.path.dirname(form_data['file_field'].name) != '':
21  
-            return HttpResponseServerError()            
  21
+            return HttpResponseServerError()
22 22
         return HttpResponse('')
23 23
     else:
24 24
         return HttpResponseServerError()
@@ -62,7 +62,8 @@ def file_upload_unicode_name(request):
62 62
     # through file save.
63 63
     uni_named_file = request.FILES['file_unicode']
64 64
     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):
66 67
         response = HttpResponseServerError()
67 68
 
68 69
     # Cleanup the object with its exotic file name immediately.
@@ -82,14 +83,14 @@ def file_upload_echo(request):
82 83
     """
83 84
     r = dict([(k, f.name) for k, f in request.FILES.items()])
84 85
     return HttpResponse(simplejson.dumps(r))
85  
-    
  86
+
86 87
 def file_upload_quota(request):
87 88
     """
88 89
     Dynamically add in an upload handler.
89 90
     """
90 91
     request.upload_handlers.insert(0, QuotaUploadHandler())
91 92
     return file_upload_echo(request)
92  
-        
  93
+
93 94
 def file_upload_quota_broken(request):
94 95
     """
95 96
     You can't change handlers after reading FILES; this view shouldn't work.

0 notes on commit c6e662c

Please sign in to comment.
Something went wrong with that request. Please try again.