Defect #30441
closedAttachments with Unicode uppercase names are not shown in wiki pages
0%
Description
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
Files
Related issues
Updated by Go MAEDA over 5 years ago
- Target version set to Candidate for next minor release
Updated by Go MAEDA over 5 years ago
- Related to Defect #27780: Case-insensitive matching fails for Unicode filenames when referring to attachments in text formatting added
Updated by Go MAEDA over 5 years ago
Evgeny Seliverstov wrote:
The problem can be fixed easily just by avoiding calling
String#downcase
inApplicationHelper#parse_inline_attachments
.
Comparing ASCII filenames with any cases should still work without changes (because ofcasecmp
).
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.
Updated by Go MAEDA over 5 years ago
- File test-30441.patch test-30441.patch added
- Target version changed from Candidate for next minor release to 4.0.4
Rewrote the test.
Updated by Go MAEDA over 5 years ago
- Subject changed from Attachments with unicode uppercase names are not shown in wiki to Attachments with Unicode uppercase names are not shown in wiki pages
- Status changed from New to Resolved
- Assignee set to Go MAEDA
- Resolution set to Fixed
Committed the patches. Thank you for reporting and fixing the issue.