]> source.dussan.org Git - redmine.git/commitdiff
Case-insensitive matching fails for Unicode filenames when referring to attachments...
authorGo MAEDA <maeda@farend.jp>
Sat, 20 Mar 2021 23:29:21 +0000 (23:29 +0000)
committerGo MAEDA <maeda@farend.jp>
Sat, 20 Mar 2021 23:29:21 +0000 (23:29 +0000)
Patch by Go MAEDA.

git-svn-id: http://svn.redmine.org/redmine/trunk@20835 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 3ffb1b51d9fddb8ce3d55f451871223b392814c1..ebac3f2a094e011c147c65f1ce807fd232757240 100644 (file)
@@ -368,8 +368,10 @@ class Attachment < ActiveRecord::Base
   end
 
   def self.latest_attach(attachments, filename)
+    return unless filename.valid_encoding?
+
     attachments.sort_by(&:created_on).reverse.detect do |att|
-      filename.casecmp(att.filename) == 0
+      filename.casecmp?(att.filename)
     end
   end
 
index 868e83f4882626ddc8ed78ae94adb2d5e16f63a6..21b5ab431de6784a52e9a03f29dea21934a321cc 100644 (file)
@@ -473,6 +473,19 @@ class AttachmentTest < ActiveSupport::TestCase
     Attachment.latest_attach(Attachment.limit(2).to_a, string)
   end
 
+  def test_latest_attach_should_support_unicode_case_folding
+    a_capital = Attachment.create!(
+      :author => User.find(1),
+      :file => mock_file(:filename => 'Ā.TXT')
+    )
+    a_small = Attachment.create!(
+      :author => User.find(1),
+      :file => mock_file(:filename => 'ā.txt')
+    )
+
+    assert_equal(a_small, Attachment.latest_attach([a_capital, a_small], 'Ā.TXT'))
+  end
+
   def test_thumbnailable_should_be_true_for_images
     skip unless convert_installed?
     assert_equal true, Attachment.new(:filename => 'test.jpg').thumbnailable?