From: hernani Date: Thu, 15 Jul 2010 10:47:40 +0000 (+0000) Subject: Fixes OSQA-142, spaces in uploaded image names = FAIL. X-Git-Tag: live~604 X-Git-Url: https://git.openstreetmap.org/osqa.git/commitdiff_plain/c6c2f8819fc57f538764f3bccc7580bc6d94e25b Fixes OSQA-142, spaces in uploaded image names = FAIL. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@530 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/views/writers.py b/forum/views/writers.py index c9b005b..74708d6 100644 --- a/forum/views/writers.py +++ b/forum/views/writers.py @@ -37,13 +37,16 @@ def upload(request):#ajax upload file to a question or answer raise UploadPermissionNotAuthorized() # check file type - file_name_suffix = os.path.splitext(f.name)[1].lower() + try: + file_name_suffix = os.path.splitext(f.name)[1].lower() + except KeyError: + raise FileTypeNotAllow() if not file_name_suffix in ('.jpg', '.jpeg', '.gif', '.png', '.bmp', '.tiff', '.ico'): raise FileTypeNotAllow() storage = FileSystemStorage(str(settings.UPFILES_FOLDER), str(settings.UPFILES_ALIAS)) - new_file_name = storage.save(f.name, f) + new_file_name = storage.save("_".join(f.name.split()), f) # check file size # byte size = storage.size(new_file_name)