]> git.p6c8.net - jirafeau/pcanterino.git/blobdiff - lib/functions.js.php
Match compound extensions such as tar.gz in disallowed_extensions
[jirafeau/pcanterino.git] / lib / functions.js.php
index efa82e5a3ff52dccbc89804b02322fa297d50082..65febf178f49b9b81ecb1904cc925f851b12bf45 100644 (file)
@@ -356,9 +356,9 @@ function control_selected_file_size(max_size, error_str)
 // just warns the user before they submit a doomed upload.
 function control_selected_file_extension(disallowed_extensions, error_str)
 {
-    f_name = document.getElementById('file_select').files[0].name.replace(/[\s.]+$/, '');
-    f_ext = f_name.includes('.') ? f_name.split('.').pop().toLowerCase() : '';
-    if (disallowed_extensions.includes(f_ext))
+    f_name = document.getElementById('file_select').files[0].name.replace(/[\s.]+$/, '').toLowerCase();
+    // suffix match so that compound extensions such as 'tar.gz' work too
+    if (disallowed_extensions.some(function (ext) { return f_name.endsWith('.' + ext); }))
     {
         // control_selected_file_size runs first: keep its error, if any, and add ours
         var error_pop = document.getElementById('error_pop');

patrick-canterino.de