Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/Template/Filters.pm
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,16 @@ sub truncate_filter_factory {
$len = $TRUNCATE_LENGTH unless defined $len;
$char = $TRUNCATE_ADDON unless defined $char;

# Length of char is the minimum length
my $lchar = length $char;
my $extra = $char;
my $CER = '[:#_A-Za-z][:A-Za-z0-9\-\_]+';

if ($char =~ /\&($CER;)/) {
$extra =~ s,\&($CER;),_,g;
$lchar = length $extra;
}

# Length of char is the minimum length
if ($len < $lchar) {
$char = substr($char, 0, $len);
$lchar = $len;
Expand Down
2 changes: 1 addition & 1 deletion lib/Template/Manual/Filters.pod
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ second argument.

Output:

I have much to say&hellip;
I have much to say on this&hellip;

=head1 repeat(iterations)

Expand Down
13 changes: 13 additions & 0 deletions t/filter.t
Original file line number Diff line number Diff line change
Expand Up @@ -975,3 +975,16 @@ foo(bar)
[% "foo(bar)" | uri %]
-- expect --
foo(bar)

-- test --
[% "I have much to say on this matter that has previously
been said on more than one occasion." | truncate(27,"&hellip;") %]
-- expect --
I have much to say on this&hellip;

-- test --
[% "I have much to say on this matter that has previously
been said on more than one occasion." | truncate(27,"&#x2026;") %]
-- expect --
I have much to say on this&#x2026;