Skip to content

Commit

Permalink
always transcode the file to utf-8
Browse files Browse the repository at this point in the history
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
tenderlove committed Jul 16, 2014
1 parent a00f547 commit 90f0cdc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions actionpack/lib/action_dispatch/http/upload.rb
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions actionpack/test/dispatch/uploaded_file_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 90f0cdc

Please sign in to comment.