Project

General

Profile

Actions

Defect #27780

closed

Case-insensitive matching fails for Unicode filenames when referring to attachments in text formatting

Defect #27780: Case-insensitive matching fails for Unicode filenames when referring to attachments in text formatting

Added by Амир Мусин almost 9 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Text formatting
Target version:
Resolution:
Fixed
Affected version:

Description

casecmp method doesn't work with Unicode symbol - https://bugs.ruby-lang.org/issues/14055
decision is to use casecmp? instead of casecmp - https://bugs.ruby-lang.org/issues/12786


Files

attachment.rb.patch (404 Bytes) attachment.rb.patch Амир Мусин, 2017-12-11 17:47
27780.patch (1.29 KB) 27780.patch Go MAEDA, 2020-10-22 16:29

Related issues 3 (0 open — 3 closed)

Related to Redmine - Patch #20369: Use String#casecmp for case insensitive comparisonClosedActions
Related to Redmine - Defect #30441: Attachments with Unicode uppercase names are not shown in wiki pagesClosedGo MAEDAActions
Related to Redmine - Feature #34142: Drop Ruby 2.3 supportClosedGo MAEDAActions

Updated by Toshi MARUYAMA almost 9 years ago Actions #1

  • Tracker changed from Patch to Defect
  • Subject changed from Attachment.rb patch to Attachment sort doesn't work with Unicode

Updated by Toshi MARUYAMA almost 9 years ago Actions #2

Could you add test?
source:trunk/test/unit/attachment_test.rb@17111#L386

Updated by Go MAEDA almost 9 years ago Actions #3

Амир Мусин, thank you for reporting the problem and providing the patch.

But the patch needs some improvements because Ruby older than 2.4 don't have casecmp? (https://github.com/ruby/ruby/blob/v2_4_0/NEWS). The upcoming Redmine 4.0.0 supports Ruby 2.2.2 and later (#25538).

Updated by Go MAEDA almost 9 years ago Actions #4

  • Related to Patch #20369: Use String#casecmp for case insensitive comparison added

Updated by Go MAEDA about 8 years ago Actions #5

  • Target version set to Candidate for next major release

We can merge this patch if Redmine migrates to Rails 6 (maybe in Redmine 5?).

Rails 6 requires Ruby 2.4.1+ by jeremy · Pull Request #32034 · rails/rails

Updated by Go MAEDA about 8 years ago Actions #6

  • Related to Feature #29914: Migrate to Rails 6.1 with Zeitwerk autoloading added

Updated by Go MAEDA over 7 years ago Actions #7

  • Related to Defect #30441: Attachments with Unicode uppercase names are not shown in wiki pages added

Updated by Go MAEDA over 7 years ago Actions #8

Go MAEDA wrote:

But the patch needs some improvements because Ruby older than 2.4 don't have casecmp? (https://github.com/ruby/ruby/blob/v2_4_0/NEWS). The upcoming Redmine 4.0.0 supports Ruby 2.2.2 and later (#25538).

We can apply the patch provided by Амир Мусин and fix the issue for Ruby >=2.4 right now if we define String#casecmp? method like the following.

Even if we define the method, the problem will not fe fixed under Ruby 2.3 because the fake String#casecmp? is not Unicode-aware unlike the genuine String#casecmp?. But I think it is OK because the Ruby team has ended support for 2.3 last month and probably many people who use the latest version of Redmine don't use such old Ruby.

We can delete the definition when Redmine has dropped the support for Ruby 2.3.

diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb
index e0559903b..0154de257 100644
--- a/config/initializers/10-patches.rb
+++ b/config/initializers/10-patches.rb
@@ -213,3 +213,12 @@ module ActionView
     end
   end
 end
+
+if RUBY_VERSION < '2.4'
+  class String
+    # bahaves like String#casecmp? but does not support Unicode
+    def casecmp?(other)
+      self.casecmp(other).zero?
+    end
+  end
+end

Updated by Go MAEDA about 6 years ago Actions #9

  • Related to deleted (Feature #29914: Migrate to Rails 6.1 with Zeitwerk autoloading)

Updated by Go MAEDA about 6 years ago Actions #10

Updated by Go MAEDA about 6 years ago Actions #11

Go MAEDA wrote:

Go MAEDA wrote:

But the patch needs some improvements because Ruby older than 2.4 don't have casecmp? (https://github.com/ruby/ruby/blob/v2_4_0/NEWS). The upcoming Redmine 4.0.0 supports Ruby 2.2.2 and later (#25538).

We can apply the patch provided by Амир Мусин and fix the issue for Ruby >=2.4 right now if we define String#casecmp? method like the following.

It is not necessary now because the trunk dropped support for Ruby 2.3 (#34142).

Updated by Go MAEDA about 6 years ago Actions #12

Added test code to Амир Мусин's patch.

Updated by Go MAEDA about 6 years ago Actions #13

  • Target version changed from Candidate for next major release to 4.2.0

Setting the target version to 4.2.0.

Updated by Marius BĂLTEANU over 5 years ago Actions #14

Looks good to me.

Updated by Go MAEDA over 5 years ago Actions #15

  • Subject changed from Attachment sort doesn't work with Unicode to Case-insensitive matching fails for Unicode filenames when referring to attachments in text formatting
  • Category changed from Attachments to Text formatting
  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the fix.

Actions

Also available in: PDF Atom