Vote #79374
完了Thumbnail macro causes attachment file not found and broken filename and link
0%
説明
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:
- 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:
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.
journals
in thumbnail macro (lib/redmine/wiki-formatting/macros.rb),
<pre>
title = options[:title] || attachment.title
</pre>
this line changes @attachment.filename@ if attachment has non empty description attribute.
In Attachment::title method,
<pre>
def title
title = filename.to_s
if description.present?
title << " (#{description})"
end
title
end
</pre>
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).
--------------------------------------------------------------------------------
I have confirmed the issue. Here is a test to catch it.
<pre><code class="diff">
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
</code></pre>
<pre>
Failure:
AttachmentTest#test_title [test/unit/attachment_test.rb:261]:
Expected: "test.png"
Actual: "test.png (Cool image)"
</pre>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Committed to the trunk and stable branches. Thank you for your contribution.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------