From 6062a0a89d50ce4afa362d2767e3a55c2801d657 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 15 Dec 2012 07:54:21 +0000 Subject: [PATCH] Merged r10885 from trunk (#12451). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.1-stable@11007 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/wiki_formatting/macros.rb | 2 +- .../redmine/wiki_formatting/macros_test.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/redmine/wiki_formatting/macros.rb b/lib/redmine/wiki_formatting/macros.rb index 23e6caf00..7d7488f1b 100644 --- a/lib/redmine/wiki_formatting/macros.rb +++ b/lib/redmine/wiki_formatting/macros.rb @@ -48,7 +48,7 @@ module Redmine def extract_macro_options(args, *keys) options = {} - while args.last.to_s.strip =~ %r{^(.+)\=(.+)$} && keys.include?($1.downcase.to_sym) + while args.last.to_s.strip =~ %r{^(.+?)\=(.+)$} && keys.include?($1.downcase.to_sym) options[$1.downcase.to_sym] = $2 args.pop end diff --git a/test/unit/lib/redmine/wiki_formatting/macros_test.rb b/test/unit/lib/redmine/wiki_formatting/macros_test.rb index 75376652a..00d9f0a8e 100644 --- a/test/unit/lib/redmine/wiki_formatting/macros_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/macros_test.rb @@ -100,6 +100,25 @@ class Redmine::WikiFormatting::MacrosTest < ActionView::TestCase assert_equal '

Hello world! Object: Issue, Called with no argument and no block of text.

', textilizable(text, :object => Issue.find(1)) end + def test_extract_macro_options_should_with_args + options = extract_macro_options(["arg1", "arg2"], :foo, :size) + assert_equal([["arg1", "arg2"], {}], options) + end + + def test_extract_macro_options_should_with_options + options = extract_macro_options(["foo=bar", "size=2"], :foo, :size) + assert_equal([[], {:foo => "bar", :size => "2"}], options) + end + + def test_extract_macro_options_should_with_args_and_options + options = extract_macro_options(["arg1", "arg2", "foo=bar", "size=2"], :foo, :size) + assert_equal([["arg1", "arg2"], {:foo => "bar", :size => "2"}], options) + end + + def test_extract_macro_options_should_parse_options_lazily + options = extract_macro_options(["params=x=1&y=2"], :params) + assert_equal([[], {:params => "x=1&y=2"}], options) + end def test_macro_exception_should_be_displayed Redmine::WikiFormatting::Macros.macro :exception do |obj, args| -- 2.39.5