aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http
diff options
context:
space:
mode:
authorDamien Mathieu <42@dmathieu.com>2011-06-14 09:59:18 +0200
committerDamien Mathieu <42@dmathieu.com>2011-06-14 14:34:30 +0200
commit383d56b5ee5da7d6e34e75677e96e0f342aa470d (patch)
treeb3ec99670c9ef4e94702e3f921553aff66adcfad /actionpack/lib/action_dispatch/http
parent954359b9c260f0e1265237c20bb3e4834a11fb9a (diff)
downloadrails-383d56b5ee5da7d6e34e75677e96e0f342aa470d.tar.gz
rails-383d56b5ee5da7d6e34e75677e96e0f342aa470d.tar.bz2
rails-383d56b5ee5da7d6e34e75677e96e0f342aa470d.zip
encode the uploaded file's name in the default external encoding - Closes #869
Diffstat (limited to 'actionpack/lib/action_dispatch/http')
-rw-r--r--actionpack/lib/action_dispatch/http/upload.rb13
1 files changed, 12 insertions, 1 deletions
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