diff options
author | Go MAEDA <maeda@farend.jp> | 2024-08-20 02:13:21 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2024-08-20 02:13:21 +0000 |
commit | 578360fdabcccea3510b6aadb6ed3a0a87d4e2d0 (patch) | |
tree | 901ac654a4554825d3ccf8a403a7f6112fa005f1 | |
parent | 65597ec1cfca87f3f0667d6e2de21621e16e2cb0 (diff) | |
download | redmine-578360fdabcccea3510b6aadb6ed3a0a87d4e2d0.tar.gz redmine-578360fdabcccea3510b6aadb6ed3a0a87d4e2d0.zip |
Add support for quoted arguments containing commas in wiki macros (#40014).
Patch by Yasu Saku (user:skys).
git-svn-id: https://svn.redmine.org/redmine/trunk@22959 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | lib/redmine/wiki_formatting/macros.rb | 7 | ||||
-rw-r--r-- | test/unit/lib/redmine/wiki_formatting/macros_test.rb | 7 |
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/redmine/wiki_formatting/macros.rb b/lib/redmine/wiki_formatting/macros.rb index a6238ef1e..f2b8c297f 100644 --- a/lib/redmine/wiki_formatting/macros.rb +++ b/lib/redmine/wiki_formatting/macros.rb @@ -38,7 +38,10 @@ module Redmine method_name = "macro_#{name}" unless macro_options[:parse_args] == false - args = args.split(',').map(&:strip) + # Split the arguments by commas, but only if the commas + # are not within double quotes + args = args.split(/\s*,\s*(?=(?:[^"]*"[^"]*")*[^"]*$)/) + .map {|i| i.gsub(/^"(.*)"$/, '\1').gsub('""', '"')} end begin @@ -57,7 +60,7 @@ module Redmine def extract_macro_options(args, *keys) options = {} while args.last.to_s.strip =~ %r{^(.+?)\=(.+)$} && keys.include?($1.downcase.to_sym) - options[$1.downcase.to_sym] = $2 + options[$1.downcase.to_sym] = $2.gsub(/^"(.*)"$/, '\1') args.pop end return [args, options] diff --git a/test/unit/lib/redmine/wiki_formatting/macros_test.rb b/test/unit/lib/redmine/wiki_formatting/macros_test.rb index 1355acef3..b385de6fc 100644 --- a/test/unit/lib/redmine/wiki_formatting/macros_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/macros_test.rb @@ -279,6 +279,13 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest end end + def test_macro_collapse_with_arg_contains_comma + text = %|{{collapse("Click here, to see the example", Hide example)\n*Collapsed* block of text\n}}| + result = textilizable(text) + assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Click here, to see the example' + assert_select_in result, 'a.collapsible.icon-expanded', :text => 'Hide example' + end + def test_macro_collapse_should_not_break_toc set_language_if_valid 'en' |