Cherry picking encoding for 3.1 #1713

Merged
merged 3 commits into from Jun 15, 2011
@@ -4,7 +4,7 @@ class UploadedFile
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 @@ def rewind
def size
@tempfile.size
end
+
@pixeltrix
pixeltrix Jun 15, 2011 Member

Extra whitespace here too.

+ 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
@@ -12,6 +12,13 @@ def test_original_filename
uf = Http::UploadedFile.new(:filename => 'foo', :tempfile => Object.new)
assert_equal 'foo', uf.original_filename
end
+
@pixeltrix
pixeltrix Jun 15, 2011 Member

Watch the extra whitespace :-)

@dmathieu
dmathieu Jun 15, 2011 Contributor

That would be textmate adding them automatically. You want me to remove them ?

@pixeltrix
pixeltrix Jun 15, 2011 Member

Leave them for the moment

@pixeltrix
pixeltrix Jun 15, 2011 Member

In future when cherry picking a bunch of small edits like this it's cleaner to git cherry-pick -x them all and then git rebase --interactive to squash them into a single commit with the original commits referenced in the squashed commit message.

+ if "ruby".encoding_aware?
+ def test_filename_should_be_in_utf_8
+ uf = Http::UploadedFile.new(:filename => 'foo', :tempfile => Object.new)
+ assert_equal "UTF-8", uf.original_filename.encoding.to_s
+ end
+ end
def test_content_type
uf = Http::UploadedFile.new(:type => 'foo', :tempfile => Object.new)