From e236d0267463d5c6ae4f982c73566d12c3089e82 Mon Sep 17 00:00:00 2001 From: Gordon Stanton Date: Fri, 5 Feb 2016 14:18:40 +1100 Subject: [PATCH] Make truncate Character Entity Reference aware - fixes bug #95707 (cherry picked from commit a9ba3869f33be68a324c7c6718081c25811724bd) Signed-off-by: Nicolas R --- lib/Template/Filters.pm | 10 +++++++++- lib/Template/Manual/Filters.pod | 2 +- t/filter.t | 13 +++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/Template/Filters.pm b/lib/Template/Filters.pm index dd52bcc5..aa0229bf 100644 --- a/lib/Template/Filters.pm +++ b/lib/Template/Filters.pm @@ -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; diff --git a/lib/Template/Manual/Filters.pod b/lib/Template/Manual/Filters.pod index 6c9fb571..802755ab 100644 --- a/lib/Template/Manual/Filters.pod +++ b/lib/Template/Manual/Filters.pod @@ -326,7 +326,7 @@ second argument. Output: - I have much to say… + I have much to say on this… =head1 repeat(iterations) diff --git a/t/filter.t b/t/filter.t index 1e8f17bb..5e784731 100644 --- a/t/filter.t +++ b/t/filter.t @@ -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,"…") %] +-- expect -- +I have much to say on this… + +-- test -- +[% "I have much to say on this matter that has previously + been said on more than one occasion." | truncate(27,"…") %] +-- expect -- +I have much to say on this… +