Subject: | Truncate filter bug |
Date: | Thu, 30 Apr 2009 17:04:21 -0700 |
To: | bug-Template-Toolkit [...] rt.cpan.org |
From: | Brian Rectanus <Brian.Rectanus [...] breach.com> |
The truncated filter does not handle $len smaller than length of $char.
Instead a negative val is passed to the substr() offset and there are
some interesting results ;)
Maybe make length($char) the minimum (untested):
sub truncate_filter_factory {
my ($context, $len, $char) = @_;
$len = 32 unless defined $len;
$char = "..." unless defined $char;
# Length of char is the minimum length
$lchar = length $char;
$len = $lchar if $len < $lchar;
return sub {
my $text = shift;
return $text if length $text <= $len;
return substr($text, 0, $len - $lchar)) . $char;
}
}
later,
-B
--
Brian Rectanus
Breach Security