allow single quote delimiters for macro parameters

This commit is contained in:
Graham Knop 2009-02-23 04:25:17 +00:00
parent af5ad84fc8
commit 65a0c7bbae
2 changed files with 38 additions and 9 deletions

View file

@ -161,26 +161,38 @@ sub _processMacro {
$parameters =~ s/^\(//;
$parameters =~ s/\)$//;
# there are two possible matches and only one will ever match at a time, so we filter out the undef ones
my @params = grep { defined $_ } ($parameters =~ /
my @params;
while ($parameters =~ /
(?<!\z) # don't try to match if we are at the end of the string
(?: # either
\s* " # white space followed by quotes
\s* " # white space followed by a double quote
( (?: # capture inside
[^"\\] # something other than a quote or backslash
[^"\\] # something other than backslash or double quote
| # or
\\. # a backslash followed by any character
) * ) # as many times as needed
" \s* # end quote and any white space
" \s* # end quote and any white space
| # or
([^,]*) # anything but a comma
\s* ' # same as above, but with single quotes
( (?:
[^'\\]
|
\\.
) * )
' \s*
| # or
([^,]*) # anything but a comma
)
(?: # followed by
\z # end of the string
| # or
, # a comma
)
/xg);
/xg) {
# three matches, only one will exist per run
push @params, defined $1 ? $1 : defined $2 ? $2 : $3;
}
for my $param (@params) {
$param =~ s/\\(.)/$1/xmsg; # deal with backslash escapes
process($session, \$param)

View file

@ -43,7 +43,7 @@ foreach my $macro (qw/
}
$session->config->addToHash('macros', "Ex'tras", "Extras");
plan tests => 33;
plan tests => 35;
my $macroText = "CompanyName: ^c;";
my $companyName = $session->setting->get('companyName');
@ -200,6 +200,23 @@ is(
"Carriage returns pass through as needed."
);
my $macroText = qq|^ReverseParams(1,'Single quoted parameters work properly',2);|;
WebGUI::Macro::process($session, \$macroText),
is(
$macroText,
"2Single quoted parameters work properly1",
"Single quoted parameters work properly."
);
my $macroText = qq|^ReverseParams(1,'Escaped single\\' quotes work',2);|;
WebGUI::Macro::process($session, \$macroText),
is(
$macroText,
"2Escaped single' quotes work1",
"Escaped single quotes work."
);
tie my %quotingEdges, 'Tie::IxHash';
%quotingEdges = (
'^VisualMacro(text);' => '@MacroCall[`text`]:',
@ -217,7 +234,7 @@ while (my ($inText, $outText) = each %quotingEdges) {
is(
$procText,
$outText,
"Nesting edge case: $inText",
"Quoting/Nesting edge case: $inText",
);
}