]> source.dussan.org Git - redmine.git/commitdiff
Merged r14473 (#20278).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 12 Sep 2015 10:51:25 +0000 (10:51 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 12 Sep 2015 10:51:25 +0000 (10:51 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.1-stable@14543 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/attachment.rb
test/unit/attachment_test.rb

index 8e3d578e5dec38af3189a62859ad305ed5d658ab..d1d7c6dd0948427ed1ac4c9a406e1864f3a60bf1 100644 (file)
@@ -294,7 +294,7 @@ class Attachment < ActiveRecord::Base
 
   def self.latest_attach(attachments, filename)
     attachments.sort_by(&:created_on).reverse.detect do |att|
-      att.filename.downcase == filename.downcase
+      filename.casecmp(att.filename) == 0
     end
   end
 
index b48ebcf3ff4b89b50cac5ce8494546ace01b0470..ffc8fe1cd95ea0cb94e7b8b538c0408d19bb4687 100644 (file)
@@ -327,6 +327,13 @@ class AttachmentTest < ActiveSupport::TestCase
     set_tmp_attachments_directory
   end
 
+  def test_latest_attach_should_not_error_with_string_with_invalid_encoding
+    string = "width:50\xFE-Image.jpg".force_encoding('UTF-8')
+    assert_equal false, string.valid_encoding?
+
+    Attachment.latest_attach(Attachment.limit(2).to_a, string)
+  end
+
   def test_thumbnailable_should_be_true_for_images
     assert_equal true, Attachment.new(:filename => 'test.jpg').thumbnailable?
   end