Skip to content

Commit

Permalink
Fixed #10967: Using a round bracket (parenthesis) in a macro. Unbalan…
Browse files Browse the repository at this point in the history
…ced parentheses can now be escaped in macro calls using the backslash character.
  • Loading branch information
hao committed Sep 14, 2009
1 parent f40992f commit a48b16d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
/*.kpf
1 change: 1 addition & 0 deletions docs/changelog/7.x.x.txt
Expand Up @@ -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?
Expand Down
4 changes: 3 additions & 1 deletion lib/WebGUI/Macro.pm
Expand Up @@ -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
Expand Down
35 changes: 34 additions & 1 deletion t/Macro.t
Expand Up @@ -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');
Expand Down Expand Up @@ -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'
''=~( '(?{' .('`' |'%') .('[' ^'-')
.('`' |'!') .('`' |',') .'"'. '\\$'
Expand Down Expand Up @@ -288,5 +320,6 @@ is(
);



END {
}
16 changes: 16 additions & 0 deletions t/Macro/Quote.t
Expand Up @@ -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;
Expand Down

0 comments on commit a48b16d

Please sign in to comment.