Defect #34046

Escaping symbols in task subject can broke export to Gantt (PNG)

Added by Kirill Trofimov 2 months ago. Updated 18 days ago.

Status:ConfirmedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Gantt
Target version:Candidate for next minor release
Resolution: Affected version:4.1.1

Description

Hello there, I think i found a problem with export Gantt to PNG. When I have task's subject with escape characters for example: "Student's Problems with new login page" I receive error (from Redmine logs):

MiniMagick::Error (`convert -size 1125x926 xc:white -stroke transparent -fill black -stroke transparent 
...
-strokewidth 1 -draw text 84,418 'Student'"'"'s Problems with new login page' -fill 
...
red -draw line 516,36 516,925 /tmp/mini_magick20200929-4913-1ne7j9r.png` failed with error:
convert-im6.q16: non-conforming drawing primitive definition `'' @ error/draw.c/RenderMVGContent/4301.
):

lib/redmine/helpers/gantt.rb:381:in `to_image'
app/controllers/gantts_controller.rb:44:in `block (2 levels) in show'
app/controllers/gantts_controller.rb:42:in `show'
lib/redmine/sudo_mode.rb:65:in `sudo_mode'

And when I except this task by filters from Gantt everything is fine. Is there any chances to fix this issue?

fixed-34046.patch Magnifier (2.52 KB) Yuichi HARADA, 2020-09-30 09:34


Related issues

Related to Redmine - Feature #30492: Replace RMagick with MiniMagick Closed

History

#1 Updated by Go MAEDA 2 months ago

  • Status changed from New to Confirmed

#2 Updated by Yuichi HARADA about 1 month ago

It used Redmine::Utils::Shell.shell_quote to escape the subject string, but it was an escaping for the string that cannot be handled by the magick-convert command.
I fixed the special character escaping process as follows.

diff --git a/lib/redmine/helpers/gantt.rb b/lib/redmine/helpers/gantt.rb
index 31956bfae..168ce43f7 100644
--- a/lib/redmine/helpers/gantt.rb
+++ b/lib/redmine/helpers/gantt.rb
@@ -400,7 +400,7 @@ module Redmine
             gc.stroke('transparent')
             gc.strokewidth(1)
             gc.draw('text %d,%d %s' % [
-              left.round + 8, 14, Redmine::Utils::Shell.shell_quote("#{month_f.year}-#{month_f.month}")
+              left.round + 8, 14, image_text_quote("#{month_f.year}-#{month_f.month}")
             ])
             left = left + width
             month_f = month_f >> 1
@@ -436,7 +436,7 @@ module Redmine
               gc.stroke('transparent')
               gc.strokewidth(1)
               gc.draw('text %d,%d %s' % [
-                left.round + 2, header_height + 14, Redmine::Utils::Shell.shell_quote(week_f.cweek.to_s)
+                left.round + 2, header_height + 14, image_text_quote(week_f.cweek.to_s)
               ])
               left = left + width
               week_f = week_f + 7
@@ -797,7 +797,7 @@ module Redmine
         params[:image].stroke('transparent')
         params[:image].strokewidth(1)
         params[:image].draw('text %d,%d %s' % [
-          params[:indent], params[:top] + 2, Redmine::Utils::Shell.shell_quote(subject)
+          params[:indent], params[:top] + 2, image_text_quote(subject)
         ])
       end

@@ -1040,10 +1040,18 @@ module Redmine
         if label
           params[:image].fill('black')
           params[:image].draw('text %d,%d %s' % [
-            params[:subject_width] + (coords[:bar_end] || 0) + 5, params[:top] + 1, Redmine::Utils::Shell.shell_quote(label)
+            params[:subject_width] + (coords[:bar_end] || 0) + 5, params[:top] + 1, image_text_quote(label)
           ])
         end
       end
+
+      def image_text_quote(text)
+        if Redmine::Platform.mswin?
+          %Q!"#{text.gsub(/(")/, '\\\\\1')}"!
+        else
+          %Q!'#{text.gsub(/(')/, '\\\\\1')}'!
+        end
+      end
     end
   end
 end

#3 Updated by Go MAEDA about 1 month ago

#4 Updated by Go MAEDA 18 days ago

  • Target version set to Candidate for next minor release

Also available in: Atom PDF