]> source.dussan.org Git - redmine.git/commitdiff
Non-ascii attachement filename fix for IE.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 10 Jan 2008 22:42:41 +0000 (22:42 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 10 Jan 2008 22:42:41 +0000 (22:42 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1053 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/application.rb
app/controllers/attachments_controller.rb
app/controllers/documents_controller.rb
app/controllers/versions_controller.rb

index 306ebc03cf0f3d762af7cc81fb10a1e64bab844c..25cf205f4de1ce076106343df95a9497352a09d5 100644 (file)
@@ -196,4 +196,9 @@ class ApplicationController < ActionController::Base
     end
     return tmp
   end
+  
+  # Returns a string that can be used as filename value in Content-Disposition header
+  def filename_for_content_disposition(name)
+    request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
+  end
 end
index 0913de529e64f14a1be42ebe87beb50a5d898953..4e87e54422d3eee80e606fa6726360e9c8e2a285 100644 (file)
@@ -21,7 +21,7 @@ class AttachmentsController < ApplicationController
 
   def download
     # images are sent inline
-    send_file @attachment.diskfile, :filename => @attachment.filename, 
+    send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
                                     :type => @attachment.content_type, 
                                     :disposition => (@attachment.image? ? 'inline' : 'attachment')
   rescue
index b37a8371a773c8d05810aaa95a69c3e27cc0e130..93f25c4952f6e5766656ca71afb3967e1d07dce2 100644 (file)
@@ -67,7 +67,8 @@ class DocumentsController < ApplicationController
   def download
     @attachment = @document.attachments.find(params[:attachment_id])
     @attachment.increment_download
-    send_file @attachment.diskfile, :filename => @attachment.filename, :type => @attachment.content_type
+    send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
+                                    :type => @attachment.content_type
   rescue
     render_404
   end 
index 1365c97e88faf20160ae7fbce46e5d9206edbeb6..df1be286956f5c3ed158393c2d76ed66b9ce9f59 100644 (file)
@@ -42,7 +42,8 @@ class VersionsController < ApplicationController
   def download
     @attachment = @version.attachments.find(params[:attachment_id])
     @attachment.increment_download
-    send_file @attachment.diskfile, :filename => @attachment.filename, :type => @attachment.content_type
+    send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
+                                    :type => @attachment.content_type
   rescue
     render_404
   end