diff options
-rw-r--r-- | app/models/attachment.rb | 2 | ||||
-rw-r--r-- | test/unit/attachment_test.rb | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 8e3d578e5..d1d7c6dd0 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -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 diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb index b48ebcf3f..ffc8fe1cd 100644 --- a/test/unit/attachment_test.rb +++ b/test/unit/attachment_test.rb @@ -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 |