From 600aa6679ed98d132fc378dfa205f482a58cceb1 Mon Sep 17 00:00:00 2001 From: Karen Tracey Date: Tue, 2 Mar 2010 21:58:49 +0000 Subject: 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 --- tests/regressiontests/file_uploads/views.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/regressiontests/file_uploads/views.py b/tests/regressiontests/file_uploads/views.py index a2053a936a..50bc3f8e65 100644 --- a/tests/regressiontests/file_uploads/views.py +++ b/tests/regressiontests/file_uploads/views.py @@ -2,7 +2,7 @@ import os from django.core.files.uploadedfile import UploadedFile from django.http import HttpResponse, HttpResponseServerError from django.utils import simplejson -from models import FileModel +from models import FileModel, UPLOAD_TO from uploadhandler import QuotaUploadHandler, ErroringUploadHandler from django.utils.hashcompat import sha_constructor from tests import UNICODE_FILENAME @@ -18,7 +18,7 @@ def file_upload_view(request): # If a file is posted, the dummy client should only post the file name, # not the full path. if os.path.dirname(form_data['file_field'].name) != '': - return HttpResponseServerError() + return HttpResponseServerError() return HttpResponse('') else: return HttpResponseServerError() @@ -62,7 +62,8 @@ def file_upload_unicode_name(request): # through file save. uni_named_file = request.FILES['file_unicode'] obj = FileModel.objects.create(testfile=uni_named_file) - if not obj.testfile.name.endswith(uni_named_file.name): + full_name = u'%s/%s' % (UPLOAD_TO, uni_named_file.name) + if not os.path.exists(full_name): response = HttpResponseServerError() # Cleanup the object with its exotic file name immediately. @@ -82,14 +83,14 @@ def file_upload_echo(request): """ r = dict([(k, f.name) for k, f in request.FILES.items()]) return HttpResponse(simplejson.dumps(r)) - + def file_upload_quota(request): """ Dynamically add in an upload handler. """ request.upload_handlers.insert(0, QuotaUploadHandler()) return file_upload_echo(request) - + def file_upload_quota_broken(request): """ You can't change handlers after reading FILES; this view shouldn't work. -- cgit v1.3