From c105522d86cf2f35182505df92ad8539e3e61563 Mon Sep 17 00:00:00 2001 From: Len Kranendonk Date: Sun, 19 Oct 2003 15:06:40 +0000 Subject: [PATCH] Fixed macro parsing bugs --- lib/WebGUI/Macro.pm | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/lib/WebGUI/Macro.pm b/lib/WebGUI/Macro.pm index 234d8fa65..a2bdfd4d8 100644 --- a/lib/WebGUI/Macro.pm +++ b/lib/WebGUI/Macro.pm @@ -46,33 +46,24 @@ These functions are available from this package: -#------------------------------------------------------------------- -# Returns a complex regular expression for matching macro patterns. -sub _nestedMacro { - my $nestedMacro = qr /\^ # Start with carat - ([^\^;()]+) # And one or more none-macro characters -tagged- - ((?: # Followed by - (??{ $parenthesis }) # a balanced parenthesis block - |(?>[^\^;]) # Or not a carat or semicolon - |(??{ $nestedMacro }) # Or a balanced carat-semicolon block - )*) # zero or more times -tagged- - ;/x; # End with a semicolon. - return $nestedMacro; -} +our $nestedMacro = qr /(\^ # Start with carat + ([^\^;()]+) # And one or more none-macro characters -tagged- + ((?: # Followed by + (??{ $parenthesis }) # a balanced parenthesis block + |(?>[^\^;]) # Or not a carat or semicolon +# |(??{ $nestedMacro }) # Or a balanced carat-semicolon block + )*) # zero or more times -tagged- + ;)/x; # End with a semicolon. -#------------------------------------------------------------------- -# Returns a regular expression for matching balanced parenthesis patterns. -sub _parenthesis { - my $parenthesis = qr /\( # Start with '(', - (?: # Followed by - (?>[^()]+) # Non-parenthesis - |(??{ $parenthesis }) # Or a balanced parenthesis block - )* # zero or more times - \)/x; # Ending with ')' - return $parenthesis; -} +our $parenthesis = qr /\( # Start with '(', + (?: # Followed by + (?>[^()]+) # Non-parenthesis + |(??{ $parenthesis }) # Or a balanced parenthesis block + )* # zero or more times + \)/x; # Ending with ')' + #------------------------------------------------------------------- =head2 filter ( html ) @@ -91,8 +82,6 @@ The segment to be filtered. sub filter { my $content = shift; - my $parenthesis = _parenthesis(); - my $nestedMacro = _nestedMacro(); while ($content =~ /($nestedMacro)/gs) { $content =~ s/\Q$1//gs; } @@ -169,9 +158,7 @@ A string of HTML to be processed. sub process { my $content = shift; - my $parenthesis = _parenthesis(); - my $nestedMacro = _nestedMacro(); - while ($content =~ /($nestedMacro)/gs) { + while ($content =~ /$nestedMacro/gs) { my ($macro, $searchString, $params) = ($1, $2, $3); next if ($searchString =~ /^\d+$/); # don't process ^0; ^1; ^2; etc. next if ($searchString =~ /^\-$/); # don't process ^-;