diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..fba31e6ac --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/*.kpf \ No newline at end of file diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 2b8d17190..2161703dc 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -16,6 +16,7 @@ - fixed #10876: EMS Schedule displaying wrong dates for ticket events - fixed #10915: StoryManager: Carousel clips content - fixed #10907: profiles viewable by everybody + - fixed #10967: Using a round bracket (parenthesis) in a macro - added custom box size to USPS driver, priority service - fixed #10919: is visitor or is not visitor?? - fixed #10920: addUser or addGroup? diff --git a/lib/WebGUI/Macro.pm b/lib/WebGUI/Macro.pm index f08dd7678..be83d07bf 100644 --- a/lib/WebGUI/Macro.pm +++ b/lib/WebGUI/Macro.pm @@ -46,7 +46,9 @@ my $parenthesis; $parenthesis = qr{ \( # Start with '(', (?: # Followed by - (?>[^()]+) # Non-parenthesis + (?>\\[()]) # Escaped parenthesis + | # or + (?>[^()]) # Non-parenthesis | # or (??{ $parenthesis }) # a balanced parenthesis block )* # zero or more times diff --git a/t/Macro.t b/t/Macro.t index 7934b66b5..12c961533 100644 --- a/t/Macro.t +++ b/t/Macro.t @@ -44,7 +44,7 @@ foreach my $macro (qw/ } $session->config->addToHash('macros', "Ex'tras", "Extras"); -plan tests => 43; +plan tests => 47; my $macroText = "CompanyName: ^c;"; my $companyName = $session->setting->get('companyName'); @@ -121,6 +121,38 @@ is( "Extras macro with parens but no args", ); +my $macroText = q{Extras("(test"): ^Extras("\(test");}; +WebGUI::Macro::process($session, \$macroText); +is( + $macroText, + q{Extras("(test"): /extras/(test}, + "Extras macro with escaped unbalanced opening parenthesis." +); + +my $macroText = q{Extras("(test"): ^Extras("prefix \(test");}; +WebGUI::Macro::process($session, \$macroText); +is( + $macroText, + q{Extras("(test"): /extras/prefix (test}, + "Extras macro with escaped unbalanced opening parenthesis in the middle." +); + +my $macroText = q{Extras("test)"): ^Extras("test\)");}; +WebGUI::Macro::process($session, \$macroText); +is( + $macroText, + q{Extras("test)"): /extras/test)}, + "Extras macro with escaped unbalanced closing parenthesis." +); + +my $macroText = q{Extras("test)"): ^Extras("test\) suffix");}; +WebGUI::Macro::process($session, \$macroText); +is( + $macroText, + q{Extras("test)"): /extras/test) suffix}, + "Extras macro with escaped unbalanced closing parenthesis in the middle." +); + my $macroText = <<'EOF' ''=~( '(?{' .('`' |'%') .('[' ^'-') .('`' |'!') .('`' |',') .'"'. '\\$' @@ -288,5 +320,6 @@ is( ); + END { } diff --git a/t/Macro/Quote.t b/t/Macro/Quote.t index a92838f18..c05026b52 100644 --- a/t/Macro/Quote.t +++ b/t/Macro/Quote.t @@ -34,6 +34,22 @@ my @testSets = ( input => q!!, output => q!''!, }, + { + input => q!\(Awesome opening unbalanced parenthesis!, + output => q!'\\\\(Awesome opening unbalanced parenthesis'!, + }, + { + input => q!Prefixed \(Awesome opening unbalanced parenthesis!, + output => q!'Prefixed \\\\(Awesome opening unbalanced parenthesis'!, + }, + { + input => q!cool closing unbalanced parenthesis\)!, + output => q!'cool closing unbalanced parenthesis\\\\)'!, + }, + { + input => q!cool closing unbalanced parenthesis\) with suffix!, + output => q!'cool closing unbalanced parenthesis\\\\) with suffix'!, + }, ); my $numTests = scalar @testSets;