]> source.dussan.org Git - redmine.git/commitdiff
Merged r22314 from trunk to 4.2-stable (#38728).
authorGo MAEDA <maeda@farend.jp>
Thu, 21 Sep 2023 00:43:10 +0000 (00:43 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 21 Sep 2023 00:43:10 +0000 (00:43 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/4.2-stable@22316 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/helpers/gantt.rb
test/unit/lib/redmine/helpers/gantt_test.rb

index bbcd501248e7b47973bb3361da921e016eee4cf5..0c9efe3c0fc1380b34ed721c8f808bf70c499df7 100644 (file)
@@ -421,7 +421,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, magick_text("#{month_f.year}-#{month_f.month}")
             ])
             left = left + width
             month_f = month_f >> 1
@@ -457,7 +457,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, magick_text(week_f.cweek.to_s)
               ])
               left = left + width
               week_f = week_f + 7
@@ -823,7 +823,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, magick_text(subject)
         ])
       end
 
@@ -1073,10 +1073,16 @@ module Redmine
           params[:image].draw('text %d,%d %s' % [
             params[:subject_width] + (coords[:bar_end] || 0) + 5,
             params[:top] + 1,
-            Redmine::Utils::Shell.shell_quote(label)
+            magick_text(label)
           ])
         end
       end
+
+      # Escape the passed string as a text argument in a draw rule for
+      # mini_magick. Note that the returned string is not shell-safe on its own.
+      def magick_text(str)
+        "'#{str.to_s.gsub(/['\\]/, '\\\\\0')}'"
+      end
     end
   end
 end
index 61b72d859aa44d4f34380cab70473a3e5915efc7..d3e7cd8c975c1ca6369ca5ddfd7bb723867449f8 100644 (file)
@@ -574,4 +574,9 @@ class Redmine::Helpers::GanttHelperTest < Redmine::HelperTest
 
     assert_equal versions.sort, Redmine::Helpers::Gantt.sort_versions!(versions.dup)
   end
+
+  def test_magick_text
+    create_gantt
+    assert_equal "'foo\\'bar\\\\baz'", @gantt.send(:magick_text, "foo'bar\\baz")
+  end
 end