Skip to content

Commit

Permalink
Item12285: Use references instead of globals
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@16187 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Dec 10, 2012
1 parent 528b1e2 commit 4599281
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions core/lib/Foswiki/Macros/MAKETEXT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ my $escape =
( $Foswiki::cfg{UserInterfaceInternationalisation}
&& ( Locale::Maketext->VERSION() < 1.23 ) );

my $max;
my $min;
my $param_error;

sub MAKETEXT {
my ( $this, $params ) = @_;

my $max;
my $min;
my $param_error;

my $str = $params->{_DEFAULT} || $params->{string} || "";
return "" unless $str;

Expand All @@ -32,10 +32,12 @@ sub MAKETEXT {
$param_error = 0;

# unescape parameters and calculate highest parameter number:
$str =~ s/~\[(\_(\d+))~\]/_validate($1, $2)/ge;
$str =~ s/~\[(\*,\_(\d+),[^,]+(,([^,]+))?)~\]/ _validate($1, $2)/ge;
$str =~ s/~\[(\_(\d+))~\]/_validate($1, $2, \$max, \$min, \$param_error)/ge;
$str =~
s/~\[(\*,\_(\d+),[^,]+(,([^,]+))?)~\]/ _validate($1, $2, \$max, \$min, \$param_error)/ge;
return $str if ($param_error);

# Escape any escapes.
$str =~ s#\\#\\\\#g if $escape;

# get the args to be interpolated.
Expand All @@ -62,19 +64,21 @@ sub MAKETEXT {
}

sub _validate {
$max = $_[1] if ( $_[1] > $max );
$min = $_[1] if ( $_[1] < $min );

${ $_[2] } = $_[1] if ( $_[1] > ${ $_[2] } ); # Record maximum param number
${ $_[3] } = $_[1] if ( $_[1] < ${ $_[3] } ); # Record minimum param number

if ( $_[1] > 100 ) {
$param_error = 1;
${ $_[4] } = 1; # Set error flag
return
"<span class=\"foswikiAlert\">Excessive parameter number $max, MAKETEXT rejected.</span>";
"<span class=\"foswikiAlert\">Excessive parameter number ${$_[2]}, MAKETEXT rejected.</span>";
}
if ( $_[1] < 1 ) {
$param_error = 1;
${ $_[4] } = 1; # Set error flag
return
"<span class=\"foswikiAlert\">Invalid parameter <code>\"$_[0]\"</code>, MAKETEXT rejected.</span>";
}
return "[$_[0]]";
return "[$_[0]]"; # Return the complete bracket parameter without escapes
}

1;
Expand Down

0 comments on commit 4599281

Please sign in to comment.