Defect #19313

Attached inline images with non-ascii file name can not be seen when text formatting is Markdown

Added by Go MAEDA over 3 years ago. Updated over 3 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:Text formatting
Target version:2.6.3
Resolution:Fixed Affected version:3.0.0

Description

If you attatch an image with non-ascii name such as "café.jpg" to an issue and make an attempt to display as inline image, you will fail if text formatting is Markdown.

The cause of the defect is that Markdown formatter generates escaped file name. ApplicationController#parse_inline_attachments (source:trunk/app/helpers/application_helper.rb@14003#L637) expects a file name without escaping.

Textile:

!café.jpg!   =>   <img src="café.jpg" alt="" />

Markdown:

![](café.jpg)   =>   <img src="caf%C3%A9.jpg" alt="">

Quick workaround is the following:

Index: app/helpers/application_helper.rb
===================================================================
--- app/helpers/application_helper.rb    (revision 14066)
+++ app/helpers/application_helper.rb    (working copy)
@@ -634,7 +634,7 @@
       text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
         filename, ext, alt, alttext = $1.downcase, $2, $3, $4
         # search for the picture in attachments
-        if found = Attachment.latest_attach(attachments, filename)
+        if found = Attachment.latest_attach(attachments, CGI.unescape(filename))
           image_url = download_named_attachment_url(found, found.filename, :only_path => only_path)
           desc = found.description.to_s.gsub('"', '')
           if !desc.blank? && alttext.blank?

Associated revisions

Revision 14080
Added by Jean-Philippe Lang over 3 years ago

Attached inline images with non-ascii file name can not be seen when text formatting is Makdown (#19313).

Patch by Go MAEDA.

Revision 14105
Added by Jean-Philippe Lang over 3 years ago

Redcarpet not available with jruby (#19313).

Revision 14106
Added by Jean-Philippe Lang over 3 years ago

Don't run test if Redcarpet is not available (#19313).

History

#1 Updated by Jean-Philippe Lang over 3 years ago

  • Target version set to 3.0.1

#2 Updated by Jean-Philippe Lang over 3 years ago

  • Status changed from New to Resolved
  • Assignee set to Jean-Philippe Lang
  • Resolution set to Fixed

Fix committed in r14080 with tests, thanks.

#3 Updated by Jean-Philippe Lang over 3 years ago

  • Status changed from Resolved to Closed
  • Target version changed from 3.0.1 to 2.6.3

#4 Updated by Toshi MARUYAMA over 3 years ago

  • Status changed from Closed to Reopened

jruby on 2.6-stable tests fail.
http://www.redmine.org/builds/logs/build_2.6-stable_mysql_jruby-1.7.6_41.html

  1) Failure:
test_attached_images_with_markdown_and_non_ascii_filename(ApplicationHelperTest)
[/var/lib/jenkins/workspace/2.6-stable/DATABASE_ADAPTER/mysql/RUBY_VER/jruby-1.7.6/test/unit/helpers/application_helper_test.rb:171]:
"<img src="/attachments/download/25/caf%C3%A9.jpg" alt="">" not found in "<p>![](café.jpg)</p>" 

#5 Updated by Jean-Philippe Lang over 3 years ago

  • Status changed from Reopened to Closed

Yes, Redcarpet is not available with jruby, test is now skipped.

#6 Updated by Go MAEDA over 3 years ago

  • Subject changed from Attached inline images with non-ascii file name can not be seen when text formatting is Makdown to Attached inline images with non-ascii file name can not be seen when text formatting is Markdown

Also available in: Atom PDF