Defect #29038

thumbnail macro causes attachment file not found and broken filename and link

Added by Toru Takahashi 5 months ago. Updated 5 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Text formatting
Target version:3.3.9
Resolution:Fixed Affected version:3.4.6

Description

Wiki's thumbnail macro seemed to break attachment's filename attribute when the attachment has non-blank description.

  • case 1
    On a wiki page attached an image file with description, and wrote twice thumbnail macros of the image file,
    then second thumbnail macro can not show thumbnail image, but file not found error.
    Sample error page is as follows:

thumbnail_twice_cause_file_not_found.png (twice thumbnails for same image)

  • case 2
    On an issue page attached an image file with description, and wrote one thumbnail macro for the image file, then attached file's filename and link is broken such that filename is shown as filename + description, and file link is same.
    Sample page is as follows:

thumbnail_cause_broken_filename_and_link.png

Case 1 is affected to wiki, issue , news, and forum.
Case 2 is affected to issue, forum.

Environment is

Environment:
  Redmine version                3.4.6.stable
  Ruby version                   2.4.1-p111 (2017-03-22) [x86_64-linux-gnu]
  Rails version                  4.2.8
  Environment                    production
  Database adapter               SQLite

  • Redmine trunk has same behavior.

thumbnail_twice_cause_file_not_found.png (twice thumbnails for same image) - twice thumbnails for same image (41.5 KB) Toru Takahashi, 2018-06-17 16:26

thumbnail_cause_broken_filename_and_link.png (40.3 KB) Toru Takahashi, 2018-06-17 16:40

attachment_title_dup_from_filename.diff Magnifier (368 Bytes) Toru Takahashi, 2018-06-17 17:12

Associated revisions

Revision 17428
Added by Go MAEDA 5 months ago

"thumbnail" macro may break filename attribute of the attachment (#29038).

Patch by Toru Takahashi.

Revision 17429
Added by Go MAEDA 5 months ago

Merged r17428 from trunk to 3.4-stable (#29038).

Revision 17430
Added by Go MAEDA 5 months ago

Merged r17428 from trunk to 3.3-stable (#29038).

History

#1 Updated by Toru Takahashi 5 months ago

in thumbnail macro (lib/redmine/wiki-formatting/macros.rb),

          title = options[:title] || attachment.title

this line changes attachment.filename if attachment has non empty description attribute.

In Attachment::title method,

  def title
    title = filename.to_s
    if description.present?
      title << " (#{description})" 
    end
    title
  end

filename.to_s returns filename itself, so when attachment has descripton,
title << " (#{description})" changes not only title but filename.

I attached a fix patch for app/models/attachment.rb to deep copy from filename attribute to title attribute to keep filename attribute from modifing title attribute.
This patch is generate under svn r17391 (3.4-stable branch).

#2 Updated by Go MAEDA 5 months ago

  • Target version set to 3.3.9

I have confirmed the issue. Here is a test to catch it.

Index: test/unit/attachment_test.rb
===================================================================
--- test/unit/attachment_test.rb    (revision 17424)
+++ test/unit/attachment_test.rb    (working copy)
@@ -258,6 +258,7 @@

     a = Attachment.new(:filename => "test.png", :description => "Cool image")
     assert_equal "test.png (Cool image)", a.title
+    assert_equal "test.png", a.filename
   end

   def test_new_attachment_should_be_editable_by_author
Failure:
AttachmentTest#test_title [test/unit/attachment_test.rb:261]:
Expected: "test.png" 
  Actual: "test.png (Cool image)" 

#3 Updated by Go MAEDA 5 months ago

  • Category changed from Attachments to Text formatting
  • Status changed from New to Resolved
  • Assignee set to Go MAEDA

#4 Updated by Go MAEDA 5 months ago

  • Status changed from Resolved to Closed
  • Resolution set to Fixed

Committed to the trunk and stable branches. Thank you for your contribution.

Also available in: Atom PDF