プロジェクト

全般

プロフィール

Vote #79770

完了

Attachments with Unicode uppercase names are not shown in wiki pages

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Attachments_19
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
19
version_id:
151
issue_org_id:
30441
author_id:
21911
assigned_to_id:
332
comments:
6
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
143
ステータス-->[Closed]

説明

Attachments with Unicode upper-case filenames (like @TestТест.png@ aka @Test\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82.png@) are not shown when included in wiki inline image macro.

Steps to reproduce:

  1. Make a wiki page
  2. Attach a file named @TestТест.png@
  3. Write in a wiki page a macro @!TestТест.png!@

Expected:

  • The image is shown as an attachment

Actual:

  • The image is not shown because an attachment is not found
  • The 404 error is in logs because Redmine tries to extract a generic resource, not an attachment

I have investigated this issue and it seems that the @ApplicationHelper#parse_inline_attachments@ method downcases filenames and then those names are compared against the database in @Attachment#latest_attach@ using @String#casecmp@. The @casecmp@ method (do not confuse with a newer @String#casecmp?@ method!) cannot deal with Unicode so the comparison fails. This bug can or can not be seen if an attachment name is downcased because @casecmp@ can successfully compare downcased strings because their byte representation is the same.

The problem can be fixed easily just by avoiding calling @String#downcase@ in @ApplicationHelper#parse_inline_attachments@.
Comparing ASCII filenames with any cases should still work without changes (because of @casecmp@).
Comparing Unicode filenames should work fine because we do not bother with changing filename at all.

I wrote a patch consisting of:

  1. Test @AttachmentTest#test_latest_should_get_with_unicode_downcase@ that reproduces a problem with an attachment search (passes before and after the fix).
  2. Test @ApplicationHelperTest#test_attached_images_with_textile_and_uppercase_non_ascii_filename@ that reproduces a problem with inline image macro (passes after the fix).
  3. Small fix to @ApplicationHelper#parse_inline_attachments@ that avoids calling @downcase@.

Related issues:

  • #27780 can fix the problem just by calling @String#casecmp?@ but it is ruby-2.4 only
  • #20369 introduced the problem in 3.2.0

About system:

Environment:
  Redmine version                3.4.7.stable
  Ruby version                   2.4.4-p296 (2018-03-28) [x86_64-darwin17]
  Rails version                  4.2.11
  Environment                    production
  Database adapter               SQLite
SCM:
  Subversion                     1.10.0
  Mercurial                      4.8.2
  Git                            2.20.1
  Filesystem
Redmine plugins:
  no plugin installed

journals

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Evgeny Seliverstov wrote:
> The problem can be fixed easily just by avoiding calling @String#downcase@ in @ApplicationHelper#parse_inline_attachments@.
> Comparing ASCII filenames with any cases should still work without changes (because of @casecmp@).
> Comparing Unicode filenames should work fine because we do not bother with changing filename at all.

I agree. The @downcase@ method in @ApplicationHelper#parse_inline_attachments@ is not necessary because the case-insensitive match is performed for @filename@ variable in Attachment#latest_attach. I think the @downcase@ method should have been removed when implementing #20369.
--------------------------------------------------------------------------------
Rewrote the test.

--------------------------------------------------------------------------------
Committed the patches. Thank you for reporting and fixing the issue.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------


related_issues

relates,Closed,27780,Case-insensitive matching fails for Unicode filenames when referring to attachments in text formatting

Admin Redmine さんが約4年前に更新

  • カテゴリAttachments_19 にセット
  • 対象バージョン4.0.4_151 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0