Skip to content

Commit

Permalink
Item12285: Sync from trunk
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/branches/Release01x01@16198 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Dec 13, 2012
1 parent f760203 commit 9a233c6
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions core/lib/Foswiki/Macros/MAKETEXT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ package Foswiki;
use strict;
use warnings;

use Locale::Maketext;
my $escape =
( $Foswiki::cfg{UserInterfaceInternationalisation}
&& $Locale::Maketext::VERSION
&& $Locale::Maketext::VERSION < 1.23 );

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

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

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

Expand All @@ -18,15 +28,22 @@ sub MAKETEXT {
$str =~ s/~~\[/~[/g;
$str =~ s/~~\]/~]/g;

$max = 0;
$min = 1;
$param_error = 0;

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

# get the args to be interpolated.
my $argsStr = $params->{args} || "";

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

my @args = split( /\s*,\s*/, $argsStr );

# fill omitted args with empty strings
Expand All @@ -47,6 +64,26 @@ s/~\[(\*,\_(\d+),[^,]+(,([^,]+))?)~\]/ $max = $2 if ($2 > $max); "[$1]"/ge;
return $result;
}

sub _validate {

#my ( $contents, $number, $max, $min, $param_error ) = @_

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

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

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down

0 comments on commit 9a233c6

Please sign in to comment.