Skip Menu |
 

This queue is for tickets about the HTML-Truncate CPAN distribution.

Report information
The Basics
Id: 67047
Status: open
Priority: 0/
Queue: HTML-Truncate

People
Owner: Nobody in particular
Requestors: TONYC [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.20
Fixed in: (no value)

Attachments
0001-sort-of-fix-breaking-final-entitites.patch



Subject: can truncate in the middle of an entity if there is more than one
Download (untitled) / with headers
text/plain 288b
Simplified from a more complex example: tony@mars:~/play$ cat html-truncate.pl #!perl -w use strict; use HTML::Truncate 0.20; my $html = 'test "x"'; my $trunc = HTML::Truncate->new; print $trunc->truncate($html, 7), "\n"; tony@mars:~/play$ perl html-truncate.pl test &q…
Download (untitled) / with headers
text/plain 106b
Attached patch fixes the problem, but the handling of the punctuation clean might be a little nasty. Tony
Subject: 0001-sort-of-fix-breaking-final-entitites.patch
From 308b7e25190ea0abc94383fe8e065d8a0116d633 Mon Sep 17 00:00:00 2001 From: Tony Cook <tony@develop-help.com> Date: Tue, 29 Mar 2011 20:06:52 +1100 Subject: [PATCH] sort of fix breaking final entitites --- lib/HTML/Truncate.pm | 5 +++-- t/entity.t | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 t/entity.t diff --git a/lib/HTML/Truncate.pm b/lib/HTML/Truncate.pm index 4a80198..4423900 100644 --- a/lib/HTML/Truncate.pm +++ b/lib/HTML/Truncate.pm @@ -102,7 +102,7 @@ sub new { { _chars => 100, _percent => undef, - _cleanly => qr/[\s[:punct:]]+\z/, + _cleanly => qr/(?!;)[\s[:punct:]]+\z/, _on_space => undef, _utf8_mode => undef, _ellipsis => '&#8230;', @@ -426,7 +426,8 @@ sub truncate { } else { - $keep = substr($txt, 0, $chars_to_keep); + #$keep = substr($txt, 0, $chars_to_keep); + ($keep) = $txt =~ /\A((?:[^&]|&[^;]+;){0,$chars_to_keep})/; } if ( my $cleaner = $self->cleanly ) diff --git a/t/entity.t b/t/entity.t new file mode 100644 index 0000000..a82bfe3 --- /dev/null +++ b/t/entity.t @@ -0,0 +1,24 @@ +#!perl +use strict; +use Test::More tests => 5; + +use HTML::Truncate; + +my $text = 'test &quot;x&quot;'; + +my $trunc = HTML::Truncate->new; + +ok($trunc, "Make truncate object"); + +is($trunc->truncate($text, 5), "test&#8230;", + "truncate to 5"); + +is($trunc->truncate($text, 6), "test &quot;&#8230;", + "truncate to 6"); + +is($trunc->truncate($text, 7), "test &quot;x&#8230;", + "truncate to 7"); + +is($trunc->truncate($text, 8), "test &quot;x&quot;&#8230;", + "truncate to 8"); + -- 1.7.2.5


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.