PATCH: Handle JavaScript attachment as a text so that it can be previewed.

Added by Wataru Hirayama over 3 years ago

Currently JavaScript attachment file can not be previewed because it's mime type is not 'text/*.'
In my environment JS attachment is found often, so it is inconvenient.

I here propose a patch that add an extention list in "is_text?" to define which file is explicitly handled as text.
Currently ".js" only, may be postscript or something like that.

Thanks.

diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index f36f7cc..3520543 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -213,8 +213,11 @@ class Attachment < ActiveRecord::Base
     end
   end

+  EXPLICIT_TEXT_EXT_LIST = %w(.js)
+
   def is_text?
-    Redmine::MimeType.is_type?('text', filename)
+    EXPLICIT_TEXT_EXT_LIST.include?(File.extname(filename).downcase) ||
+      Redmine::MimeType.is_type?('text', filename)
   end

   def is_diff?