Defect #44789
openGantt PNG export fails with ImageMagick 7.1.2 when a subject contains an apostrophe
Description
Since ImageMagick 7.1.2, the Gantt PNG export returns a 500 error as soon as a project, version or issue subject shown in the chart contains a single quote (').
Redmine::Helpers::Gantt#magick_text (introduced by #38728) escapes single quotes with a backslash ('It\'s'). ImageMagick 7.1.2's MVG parser no longer accepts \' inside a quoted string and stops at the escaped quote:
MiniMagick::Error (`magick -size 763x108 xc:white ... -draw text 44,80 'Suivi des demandes d\'améliorations' ... /tmp/mini_magick20261123-439429-6rq2ay.png` failed with status: 1 and error: magick: non-conforming drawing primitive definition `améliorations' @ error/draw.c/RenderMVGContent/4563. ): lib/redmine/helpers/gantt.rb:421:in `to_image' app/controllers/gantts_controller.rb:46:in `block (2 levels) in show' app/controllers/gantts_controller.rb:42:in `show'
Steps to reproduce¶
- Create a version (or an issue) whose name contains an apostrophe, e.g. "It's a test".
- Open the project Gantt and click "PNG" at the bottom of the page.
- The result is a 500 Internal Server Error.
ImageMagick alone reproduces it:
$ magick -size 200x50 xc:white -draw "text 4,40 'It\'s'" /tmp/t.png magick: non-conforming drawing primitive definition `s'' @ error/draw.c/RenderMVGContent/4563. $ magick -size 200x50 xc:white -draw "text 4,40 \"It's\"" /tmp/t.png # OK $ magick -size 200x50 xc:white -draw "text 4,40 'a\\b'" /tmp/t.png # OK, backslash escaping still works
Escaping a double quote inside a double-quoted string ("a\"b") fails the same way, so switching the quote character only moves the problem.
Environment¶
- Redmine 7.0.3.stable (the code is the same on trunk:
lib/redmine/helpers/gantt.rb,magick_text) - Ruby 3.3.8, mini_magick 5.2.0
- ImageMagick 7.1.2-18 Q16 (Ubuntu 26.04 package
imagemagick 8:7.1.2.18+dfsg1-1)
Proposed fix¶
Workaround in use on our instance: replace the ASCII apostrophe with the typographic apostrophe (U+2019) before quoting. The rendered text looks almost the same and the command works with every ImageMagick version:
def magick_text(str)
- "'#{str.to_s.gsub(/['\\]/, '\\\\\0')}'"
+ "'#{str.to_s.tr("'", "\u2019").gsub(/[\\]/, '\\\\\0')}'"
end
A cleaner fix could quote with double quotes when the text contains ' but no ", and fall back to the replacement above only when the text contains both kinds of quote.
No data to display