Permalink
Browse files

always transcode the file to utf-8

people may be passing filenames to the constructor that are not utf-8,
but they will assome that calling `original_filename` returns utf-8
(because that's what it used to do).
  • Loading branch information...
1 parent a00f547 commit 90f0cdc906fcec77937363c87cba45f3802ac858 @tenderlove tenderlove committed Jul 16, 2014
Showing with 7 additions and 0 deletions.
  1. +1 −0 actionpack/lib/action_dispatch/http/upload.rb
  2. +6 −0 actionpack/test/dispatch/uploaded_file_test.rb
@@ -28,6 +28,7 @@ def initialize(hash) # :nodoc:
raise(ArgumentError, ':tempfile is required') unless @tempfile
@original_filename = hash[:filename]
+ @original_filename &&= @original_filename.encode "UTF-8"
@content_type = hash[:type]
@headers = hash[:head]
end
@@ -18,6 +18,12 @@ def test_filename_should_be_in_utf_8
assert_equal "UTF-8", uf.original_filename.encoding.to_s
end
+ def test_filename_should_always_be_in_utf_8
+ uf = Http::UploadedFile.new(:filename => 'foo'.encode(Encoding::SHIFT_JIS),
+ :tempfile => Object.new)
+ assert_equal "UTF-8", uf.original_filename.encoding.to_s
+ end
+
def test_content_type
uf = Http::UploadedFile.new(:type => 'foo', :tempfile => Object.new)
assert_equal 'foo', uf.content_type

0 comments on commit 90f0cdc

Please sign in to comment.