Skip to content

Commit

Permalink
Make truncate Character Entity Reference aware - fixes bug #95707
Browse files Browse the repository at this point in the history
(cherry picked from commit a9ba3869f33be68a324c7c6718081c25811724bd)
Signed-off-by: Nicolas R <nicolas@atoomic.org>
  • Loading branch information
Gordon Stanton authored and atoomic committed Apr 28, 2024
1 parent bff44ff commit e236d02
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
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;

0 comments on commit e236d02

Please sign in to comment.