ソフトウェアエンジニアリング - バグ #7
RedmineのWiki記法でthumbnailマクロを使うと、使用した添付ファイル画像のリンクが壊れる
2014/03/12 22:47 - 高橋 徹 ステータス: フィードバック 開始日: 2014/03/12 優先度: 通常 期日: 担当者: 進捗率: 50% カテゴリ: 予定工数: 0.00時間 対象バージョン: 作業時間: 0.00時間 重要度: 説明 thumbnailマクロで指定した添付画像ファイルのリンクにコメントが結合してしまい、リンクが404となる。 例としてこのチケットに画像ファイルを添付し、thumbnailマクロで指定した。 144 関連するチケット: 関連している バグ #82: Redmineで同じ添付ファイルを指すthumbnailマクロを2つ記述すると2つ目... 新規 2018/06/17 履歴 #1 - 2014/03/12 22:49 - 高橋 徹 - 説明 を更新 #2 - 2014/03/12 23:39 - 高橋 徹 添付ファイルのリンクを生成していると思われる箇所 app/views/issues/show.html.erb85 <%= link_to_attachments @issue, :thumbnails => true %>
link_to_attachmentsを定義している箇所を捜索 app/helpers/attachments_helper.rb
25 def link_to_attachments(container, options = {}) 26 options.assert_valid_keys(:author, :thumbnails) 27
28 if container.attachments.any?
29 options = {:deletable => container.attachments_deletable?, :author => true}.merge(options) 30 render :partial => 'attachments/links',
31 :locals => {:attachments => container.attachments, :options => options, :thumbnails => (options[:thumbnails] && Setting.thumbnails_en abled?)}
32 end
33 end
30行目のrender :partialで、リンクのレンダリングはapp/views/attachments/_links.html.erbに委譲している。
1 <div class="attachments">
2 <% for attachment in attachments %>
3 <p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> 4 <% if attachment.is_text? %>
5 <%= link_to image_tag('magnifier.png'),
6 :controller => 'attachments', :action => 'show',
7 :id => attachment, :filename => attachment.filename %> 8 <% end %>
10 <span class="size">(<%= number_to_human_size attachment.filesize %>)</span> 11 <% if options[:deletable] %>
12 <%= link_to image_tag('delete.png'), attachment_path(attachment),
13 :data => {:confirm => l(:text_are_you_sure)},
14 :method => :delete,
15 :class => 'delete',
16 :title => l(:button_delete) %>
17 <% end %>
18 <% if options[:author] %>
19 <span class="author"><%= h(attachment.author) %>, <%= format_time(attachment.created_on) %></span> ment.created_on) %></span>
20 <% end %> 21 </p> 22 <% end %>
23 <% if defined?(thumbnails) && thumbnails %>
24 <% images = attachments.select(&:thumbnailable?) %> 25 <% if images.any? %>
26 <div class="thumbnails">
27 <% images.each do |attachment| %>
28 <div><%= thumbnail_tag(attachment) %></div> 29 <% end %> 30 </div> 31 <% end %> 32 <% end %> 33 </div> このファイルの中で懸案のリンクを生成しているのは
3 <p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
link_to_attachmentを定義しているファイルを検索すると、app/helpers/application_helper.rbであった。
94 def link_to_attachment(attachment, options={})
95 text = options.delete(:text) || attachment.filename
96 route_method = options.delete(:download) ? :download_named_attachment_p ath : :named_attachment_path 97 html_options = options.slice!(:only_path)
98 url = send(route_method, attachment, attachment.filename, options) 99 link_to text, url, html_options
#3 - 2014/03/12 23:46 - 高橋 徹
app/helpers/application_helper.rb にデバッグ用のprintを埋め込んだ
99 print("QQQ)text=#{text}\n") 100 link_to text, url, html_options
print文の結果は次のとおり
QQQ)text=片倉小十郎.jpg (戦国BASARAの片倉小十郎、伊達政宗の宰相)
この時点で、ファイル名がおかしい。
#4 - 2014/03/14 11:11 - 高橋 徹 app/helpers/application_helper.rb
95 text = options.delete(:text) || attachment.filename
のところでデバッグプリントを埋め込み調べると、 QQQ)attachment.filename=片倉小十郎.jpg (戦国BASARAの片倉小十郎、伊達政宗の宰相) QQQ)options.delete(:text)= となった。これは引数に渡されてくるattachmentの問題だ。呼び出し元は、 app/views/attachments/_links.html.erb 1 <div class="attachments">
2 <% for attachment in attachments %>
3 <p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
で、さらにここを呼び出す元は app/helpers/attachments_helper.rb
30 render :partial => 'attachments/links',
31 :locals => {:attachments => container.attachments, :options => options, :thumbnails => (options[:thumbnails] && Setting.thumbnai ls_enabled?)}
と、
container.attachments
が指定されている。containerをここの関数link_to_attachmentsに渡している元は、 app/views/issues/show.html.erb
の@issue部分である。
ここで、container.attachmentsは、モデルのattachmentのリストであろうと検討をつけ、app/models/attachment.rbを眺めてみる。
うむ、さっぱり分からん。app/helpers/application_helper.rbの次のメソッドの引数attachmentを詳細に見ることにした。
94 def link_to_attachment(attachment, options={})
++ print("QQQ)attachment.inspect=#{attachment.inspect}\n")
実行結果は
QQQ)attachment.inspect=#<Attachment id: 1, container_id: 2, container_type: "WikiPage", filename: "片倉小十郎.jpg (戦国BASARAの片倉小十郎、 伊達政宗の宰相)", disk_filename: "140303000143_0606daee01577da6c199ba439c7ef40e.jpg", filesize: 74596, content_type: nil, digest: "08ad4 964675bb6f3bb70a6c0fde40af4", downloads: 0, author_id: 1, created_on: "2014-03-02 15:01:43", description: "戦国BASARAの片倉小十郎、伊 達政宗の宰相", disk_directory: "2014/03">
となり、filenameが、ファイル名+' '+'('+descriptionの内容+')' となっている。 Wikiページのthumbnailマクロを削除して実行すると
QQQ)attachment.inspect=#<Attachment id: 1, container_id: 2, container_type: "WikiPage", filename: "片倉小十郎.jpg", disk_filename: "140303000 143_0606daee01577da6c199ba439c7ef40e.jpg", filesize: 74596, content_type: nil, digest: "08ad4964675bb6f3bb70a6c0fde40af4", downloads:
0, author_id: 1, created_on: "2014-03-02 15:01:43", description: "戦国BASARAの片倉小十郎、伊達政宗の宰相", disk_directory: "2014/03">
となり、filenameが、ファイル名となっている。MySQLのデータベースを調べてもthumbnailマクロの有無に関わらずfilenameは変わらない。 そこで、これは実行時にフックか何かthumbnailの存在によって働きかけているのかと推測し、'thumbnail'の言葉を検索し、app/controllers/attach ments_controller.rb が怪しそうと目星をつけて調べてみる。 ちょっとわからない・・・ うむ・・・ #5 - 2014/03/16 13:32 - 高橋 徹 - ステータス を 新規 から 進行中 に変更 - 進捗率 を 0 から 50 に変更
#6 - 2015/11/20 20:44 - 高橋 徹 - ステータス を 進行中 から 終了 に変更 - 進捗率 を 50 から 100 に変更 Redmine 3.0.3ではこのバグが解消している。 #7 - 2018/06/17 20:48 - 高橋 徹 redmine 3.4ではこのバグが復活している。 #8 - 2018/06/17 20:49 - 高橋 徹 - 関連している バグ #82: Redmineで同じ添付ファイルを指すthumbnailマクロを2つ記述すると2つ目でnot foundエラーとなる を追加 #9 - 2018/06/17 20:49 - 高橋 徹 - ステータス を 終了 から フィードバック に変更 - 進捗率 を 100 から 50 に変更 ファイル alos-1.png (陸域観測技術衛星「だいち」(ALOS) 93.7 KB 2014/03/12 高橋 徹