FIX: Composer upload icon regression because of HEIC

FIX: Composer upload icon regression because of HEIC

Now that HEIC conversion is enabled by default we need to update a few file extension checks to include heic and heif` formats.

https://meta.discourse.org/t/-/144326/23?u=blake

bug reported here:

https://meta.discourse.org/t/-/161197?u=blake

diff --git a/app/assets/javascripts/discourse/app/controllers/upload-selector.js b/app/assets/javascripts/discourse/app/controllers/upload-selector.js
index 32e834a..5088922 100644
--- a/app/assets/javascripts/discourse/app/controllers/upload-selector.js
+++ b/app/assets/javascripts/discourse/app/controllers/upload-selector.js
@@ -56,7 +56,7 @@ export default Controller.extend(ModalFunctionality, {
         const imageUrl = this.imageUrl || "";
         const toolbarEvent = this.toolbarEvent;
 
-        if (imageUrl.match(/\.(jpg|jpeg|png|gif)$/)) {
+        if (imageUrl.match(/\.(jpg|jpeg|png|gif|heic|heif)$/)) {
           toolbarEvent.addText(`![](${imageUrl})`);
         } else {
           toolbarEvent.addText(imageUrl);
diff --git a/app/assets/javascripts/discourse/app/lib/uploads.js b/app/assets/javascripts/discourse/app/lib/uploads.js
index 83bc9ec..d71784b 100644
--- a/app/assets/javascripts/discourse/app/lib/uploads.js
+++ b/app/assets/javascripts/discourse/app/lib/uploads.js
@@ -113,7 +113,7 @@ function validateUploadedFile(file, opts) {
   return true;
 }
 
-const IMAGES_EXTENSIONS_REGEX = /(png|jpe?g|gif|svg|ico)/i;
+const IMAGES_EXTENSIONS_REGEX = /(png|jpe?g|gif|svg|ico|heic|heif)/i;
 
 function extensionsToArray(exts) {
   return exts
@@ -177,7 +177,7 @@ export function authorizedExtensions(staff, siteSettings) {
 
 function authorizedImagesExtensions(staff, siteSettings) {
   return authorizesAllExtensions(staff, siteSettings)
-    ? "png, jpg, jpeg, gif, svg, ico"
+    ? "png, jpg, jpeg, gif, svg, ico, heic, heif"
     : imagesExtensions(staff, siteSettings).join(", ");
 }
 

GitHub sha: ba9fbb34

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/upload-icon-should-be-image-icon/161197/4