Checking filename and extension of subtitle uploaded
authorsaksham1115 <saksham115@gmail.com>
Wed, 27 Jul 2016 17:28:56 +0000 (17:28 +0000)
committersaksham1115 <saksham115@gmail.com>
Wed, 27 Jul 2016 17:28:56 +0000 (17:28 +0000)
mediagoblin/plugins/custom_subtitles/views.py

index 3d75b0aea1e5cc7e495862a17feca00067cdb485..36db2e8b7ac9cb1f8c03264e3ba3d1a18079930c 100644 (file)
@@ -45,6 +45,8 @@ UNSAFE_MIMETYPES = [
 @user_may_delete_media
 @require_active_login
 def edit_subtitles(request, media):
+    allowed_extensions = ['aqt','gsub','jss','sub','ttxt','pjs','psb',
+                        'rt','smi','stl','ssf','srt','ssa','ass','usf','vtt','lrc']
     form = forms.EditSubtitlesForm(request.form)
 
     # Add any subtitles
@@ -58,7 +60,23 @@ def edit_subtitles(request, media):
         else:
             public_filename = secure_filename(
                     request.files['subtitle_file'].filename)
+        filepath = request.files['subtitle_file'].filename
+        if filepath.count('.') != 1: # Not allowing double extensions or no extensions
+            messages.add_message(
+            request,
+            messages.ERROR,
+            ("Check the filename"))
 
+            return redirect(request,
+                            location=media.url_for_self(request.urlgen))
+        elif filepath.split('.')[:-1] not in allowed_extensions :
+            messages.add_message(
+            request,
+            messages.ERROR,
+            ("Invalid subtitle file"))
+
+            return redirect(request,
+                            location=media.url_for_self(request.urlgen))
         subtitle_public_filepath \
             = mg_globals.public_store.get_unique_filepath(
             ['media_entries', six.text_type(media.id), 'subtitle',