From 383d56b5ee5da7d6e34e75677e96e0f342aa470d Mon Sep 17 00:00:00 2001 From: Damien Mathieu <42@dmathieu.com> Date: Tue, 14 Jun 2011 09:59:18 +0200 Subject: encode the uploaded file's name in the default external encoding - Closes #869 --- actionpack/lib/action_dispatch/http/upload.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/http/upload.rb b/actionpack/lib/action_dispatch/http/upload.rb index 37effade4f..ed6140dac5 100644 --- a/actionpack/lib/action_dispatch/http/upload.rb +++ b/actionpack/lib/action_dispatch/http/upload.rb @@ -4,7 +4,7 @@ module ActionDispatch attr_accessor :original_filename, :content_type, :tempfile, :headers def initialize(hash) - @original_filename = hash[:filename] + @original_filename = encode_filename(hash[:filename]) @content_type = hash[:type] @headers = hash[:head] @tempfile = hash[:tempfile] @@ -30,6 +30,17 @@ module ActionDispatch def size @tempfile.size end + + private + def encode_filename(filename) + # Encode the filename in the default_external encoding, unless it is nil or we're in 1.8 + if "ruby".encoding_aware? && filename + encoding = Encoding.default_external + filename.force_encoding(encoding) + else + filename + end + end end module Upload -- cgit v1.2.3 From 383fd143bf6b81d3a1352ddaebb7b4e8beac8b37 Mon Sep 17 00:00:00 2001 From: Damien Mathieu <42@dmathieu.com> Date: Tue, 14 Jun 2011 16:58:06 +0200 Subject: all requests are utf-8. Don't use the external encoding. --- actionpack/lib/action_dispatch/http/upload.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/http/upload.rb b/actionpack/lib/action_dispatch/http/upload.rb index ed6140dac5..a15ad28f16 100644 --- a/actionpack/lib/action_dispatch/http/upload.rb +++ b/actionpack/lib/action_dispatch/http/upload.rb @@ -33,10 +33,9 @@ module ActionDispatch private def encode_filename(filename) - # Encode the filename in the default_external encoding, unless it is nil or we're in 1.8 + # Encode the filename in the utf8 encoding, unless it is nil or we're in 1.8 if "ruby".encoding_aware? && filename - encoding = Encoding.default_external - filename.force_encoding(encoding) + filename.force_encoding("UTF-8").encode! else filename end -- cgit v1.2.3