From 9f7b529495f90d44714a77463112df48ce1f24d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 19 Oct 2016 18:42:24 +0200 Subject: [PATCH] FIX: properly detect when attachments are allowed --- app/assets/javascripts/discourse/lib/utilities.js.es6 | 4 ++-- test/javascripts/lib/utilities-test.js.es6 | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/utilities.js.es6 b/app/assets/javascripts/discourse/lib/utilities.js.es6 index b1b124518bc..a46fdb0c8c6 100644 --- a/app/assets/javascripts/discourse/lib/utilities.js.es6 +++ b/app/assets/javascripts/discourse/lib/utilities.js.es6 @@ -267,12 +267,12 @@ export function isAnImage(path) { export function allowsImages() { return authorizesAllExtensions() || - (/(png|jpe?g|gif|bmp|tiff?|svg|webp|ico)/i).test(authorizedExtensions()); + (/\.(png|jpe?g|gif|bmp|tiff?|svg|webp|ico)/i).test(authorizedExtensions()); } export function allowsAttachments() { return authorizesAllExtensions() || - !(/((png|jpe?g|gif|bmp|tiff?|svg|web|ico)(,\s)?)+$/i).test(authorizedExtensions()); + !/^(\.(png|jpe?g|gif|bmp|tiff?|svg|webp|ico)(,\s)?)+$/i.test(authorizedExtensions()); } export function displayErrorForUpload(data) { diff --git a/test/javascripts/lib/utilities-test.js.es6 b/test/javascripts/lib/utilities-test.js.es6 index 59281334fc4..fd3583de8c0 100644 --- a/test/javascripts/lib/utilities-test.js.es6 +++ b/test/javascripts/lib/utilities-test.js.es6 @@ -164,13 +164,13 @@ test("avatarImg", function() { }); test("allowsAttachments", function() { - Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif"; + Discourse.SiteSettings.authorized_extensions = ".jpg, .jpeg, .gif"; not(allowsAttachments(), "no attachments allowed by default"); - Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif|*"; + Discourse.SiteSettings.authorized_extensions = ".jpg, .jpeg, .gif, *"; ok(allowsAttachments(), "attachments are allowed when all extensions are allowed"); - Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif|pdf"; + Discourse.SiteSettings.authorized_extensions = ".jpg, .jpeg, .gif, .pdf"; ok(allowsAttachments(), "attachments are allowed when at least one extension is not an image extension"); });