diff options
author | José Valim <jose.valim@gmail.com> | 2011-06-14 08:13:15 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-06-14 08:13:15 -0700 |
commit | deff5977d4ef046106ab5537ffd2eaceceeb1b86 (patch) | |
tree | b7fe92fbb0af83d3fb757a09773a903105849182 /actionpack/lib | |
parent | 954359b9c260f0e1265237c20bb3e4834a11fb9a (diff) | |
parent | 383fd143bf6b81d3a1352ddaebb7b4e8beac8b37 (diff) | |
download | rails-deff5977d4ef046106ab5537ffd2eaceceeb1b86.tar.gz rails-deff5977d4ef046106ab5537ffd2eaceceeb1b86.tar.bz2 rails-deff5977d4ef046106ab5537ffd2eaceceeb1b86.zip |
Merge pull request #1689 from dmathieu/utf8-filename
Encode the uploaded file's name in utf8 - Closes #869
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/http/upload.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/upload.rb b/actionpack/lib/action_dispatch/http/upload.rb index 37effade4f..a15ad28f16 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,16 @@ module ActionDispatch def size @tempfile.size end + + private + def encode_filename(filename) + # Encode the filename in the utf8 encoding, unless it is nil or we're in 1.8 + if "ruby".encoding_aware? && filename + filename.force_encoding("UTF-8").encode! + else + filename + end + end end module Upload |