プロジェクト

全般

プロフィール

Vote #79374

完了

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

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

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

0%

予定工数:
category_id:
26
version_id:
142
issue_org_id:
29038
author_id:
137958
assigned_to_id:
332
comments:
5
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
141
ステータス-->[Closed]

説明

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 の実行中にエラーが発生しました (添付ファイル thumbnail_twice_cause_file_not_found.png が見つかりません)

  • 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 の実行中にエラーが発生しました (添付ファイル 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.

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.
--------------------------------------------------------------------------------

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

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

  • カテゴリText formatting_26 にセット
  • 対象バージョン3.3.9_142 にセット

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

いいね!0
いいね!0