From 3aeca53c85981fa46d61b41a7cf648d90637eb62 Mon Sep 17 00:00:00 2001 From: dunkyp Date: Tue, 6 Nov 2012 17:47:48 +0000 Subject: [PATCH] fixes the inability to upload non ascii filenames, werkzeug strips all non ascii chars and returns an empty string. This checks if the filename contains non asciis and if it does generates a uuid for filename. Also the request version of filename is used for generating alternative title for upload cherry-picked from dunkyp. fixed conflicts and missing import. --- mediagoblin/submit/views.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 64e6791b..0fe280f1 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -19,6 +19,7 @@ import mediagoblin.mg_globals as mg_globals from os.path import splitext import logging +import uuid _log = logging.getLogger(__name__) @@ -53,6 +54,10 @@ def submit_start(request): try: filename = request.files['file'].filename + # If the filename contains non ascii generate a unique name + if not all(ord(c) < 128 for c in filename): + filename = unicode(uuid.uuid4()) + splitext(filename)[-1] + # Sniff the submitted media to determine which # media plugin should handle processing media_type, media_manager = sniff_media( @@ -63,7 +68,7 @@ def submit_start(request): entry.media_type = unicode(media_type) entry.title = ( unicode(submit_form.title.data) - or unicode(splitext(filename)[0])) + or unicode(splitext(request.files['file'].filename)[0])) entry.description = unicode(submit_form.description.data) -- 2.25.1