プロジェクト

全般

プロフィール

Vote #76533

完了

Wrong syntax for resizing inline images will throw a 500 error

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

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

0%

予定工数:
category_id:
26
version_id:
103
issue_org_id:
20278
author_id:
131681
assigned_to_id:
1
comments:
5
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

Given the following Textile code:

|_.Text|
|!width:50%FE-Image.jpg!|

will throw a 500 error in Redmine with an attachment file called @FE-Image.jpg@ after saving.

ActionView::Template::Error
invalid byte sequence in UTF-8

Stacktrace (most recent call first):

  attachment.rb:259:in `downcase'
    |att| att.filename.downcase == filename.downcase
  attachment.rb:259:in `block in latest_attach'
    |att| att.filename.downcase == filename.downcase
  attachment.rb:258:in `each'
    attachments.sort_by(&:created_on).reverse.detect {
  attachment.rb:258:in `detect'
    attachments.sort_by(&:created_on).reverse.detect {
  attachment.rb:258:in `latest_attach'
    attachments.sort_by(&:created_on).reverse.detect {
  application_helper.rb:657:in `block in parse_inline_attachments'
    if found = Attachment.latest_attach(attachments, CGI.unescape(filename))
  application_helper.rb:654:in `gsub!'
    text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
  application_helper.rb:654:in `parse_inline_attachments'
    text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
  application_helper.rb:605:in `block (2 levels) in textilizable'
    send method_name, text, project, obj, attr, only_path, options
  application_helper.rb:604:in `each'
    [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
  application_helper.rb:604:in `block in textilizable'
    [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
  application_helper.rb:625:in `parse_non_pre_blocks'
    yield text

Using the correct syntax:

|_.Text|
|!{width:50%}FE-Image.jpg!|

will display the correct image downsized to 50%.
Is there a way to catch such user-generated error?


journals

Although this is not a solution to the root of the error, we can avoid the error and save some cycles.
(String#casecmp is much faster than calling String#downcase twice)

<pre><code class="diff">
Index: app/models/attachment.rb
===================================================================
--- app/models/attachment.rb (revision 14445)
+++ app/models/attachment.rb (working copy)
@@ -294,7 +294,7 @@

def self.latest_attach(attachments, filename)
attachments.sort_by(&:created_on).reverse.detect do |att|
- att.filename.downcase == filename.downcase
+ filename.casecmp(att.filename)
end
end
</code></pre>
--------------------------------------------------------------------------------
Sorry, workaround on #20278#note-1 is wrong.

Should be replaced with the following:

<pre><code class="diff">
Index: app/models/attachment.rb
===================================================================
--- app/models/attachment.rb (revision 14445)
+++ app/models/attachment.rb (working copy)
@@ -294,7 +294,7 @@

def self.latest_attach(attachments, filename)
attachments.sort_by(&:created_on).reverse.detect do |att|
- att.filename.downcase == filename.downcase
+ filename.casecmp(att.filename) == 0
end
end
</code></pre>
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Fix committed with a test in r14473, thanks.
--------------------------------------------------------------------------------
Merged.
--------------------------------------------------------------------------------


related_issues

relates,Closed,20369,Use String#casecmp for case insensitive comparison

Admin Redmine さんが3年以上前に更新

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

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

いいね!0
いいね!0