Skip Menu |

This queue is for tickets about the podlators CPAN distribution.

Report information
The Basics
Id: 6699
Status: resolved
Priority: 0/
Queue: podlators

People
Owner: RRA [...] cpan.org
Requestors: len.charest [...] jpl.nasa.gov
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 1.26
  • 1.27
Fixed in: 2.00



Subject: Incorrect length calc in Pod::Text::Termcap::wrap
Environment: This is perl, v5.8.0 built for i386-linux-thread-multi $Pod::Text::Termcap::VERSION is 1.10 Summary: when computing the length of the remaining text in Pod::Text::Termcap::wrap, the characters that make up terminal control sequences (e.g., $$self{BOLD}) are included in the total. These sequences are "invisible" for the purpose of word wrapping, so they should NOT be included in the calculated length. The attached patch fixes the problem via a helper function named visible_length() -- which returns the length of its first arg less the length of all terminal control sequences. I'm using v1.10, but I've verified that this problem exists in v1.11 as well.
*** /usr/lib/perl5/5.8.0/Pod/Text/Termcap.pm 2003-08-13 09:17:12.000000000 -0700 --- Termcap.pm 2004-06-21 14:39:20.000000000 -0700 *************** *** 97,123 **** $self->output ($$self{BOLD} . $code . $$self{NORM}); } ! # Override the wrapping code to igore the special sequences. sub wrap { my $self = shift; local $_ = shift; my $output = ''; my $spaces = ' ' x $$self{MARGIN}; my $width = $$self{width} - $$self{MARGIN}; ! my $code = "(?:\Q$$self{BOLD}\E|\Q$$self{UNDL}\E|\Q$$self{NORM}\E)"; ! while (length > $width) { ! if (s/^((?:$code?[^\n]){0,$width})\s+// ! || s/^((?:$code?[^\n]){$width})//) { ! $output .= $spaces . $1 . "\n"; ! } else { ! last; ! } } $output .= $spaces . $_; $output =~ s/\s+$/\n\n/; $output; } ############################################################################## # Module return value and documentation --- 97,133 ---- $self->output ($$self{BOLD} . $code . $$self{NORM}); } ! # Override the wrapping code to ignore the special sequences. sub wrap { my $self = shift; local $_ = shift; my $output = ''; my $spaces = ' ' x $$self{MARGIN}; my $width = $$self{width} - $$self{MARGIN}; ! my $invisible = "\Q$$self{BOLD}\E|\Q$$self{UNDL}\E|\Q$$self{NORM}\E"; ! my $code = "(?:$invisible)"; ! my $length = visible_length($_, $invisible); ! while ($length > $width) { ! if (s/^((?:$code?[^\n]){0,$width})\s+// ! || s/^((?:$code?[^\n]){$width})//) { ! $output .= $spaces . $1 . "\n"; ! $length = visible_length($_, $invisible); ! } else { ! last; ! } } $output .= $spaces . $_; $output =~ s/\s+$/\n\n/; $output; } + sub visible_length { + my ($text, $invisible) = @_; + my $sum = 0; + while ($text =~ /$invisible/g) { $sum += length($&); } + length $text - $sum; + } + ############################################################################## # Module return value and documentation
From: len.charest [...] jpl.nasa.gov
[guest - Mon Jun 21 17:44:06 2004]: Show quoted text
> The attached patch fixes the problem [...]
Ugh. The first patch file has a bug of its own. :-( See the attached patched-patch.
*** /usr/lib/perl5/5.8.0/Pod/Text/Termcap.pm 2003-08-13 09:17:12.000000000 -0700 --- Termcap.pm 2004-06-21 14:52:59.000000000 -0700 *************** *** 97,123 **** $self->output ($$self{BOLD} . $code . $$self{NORM}); } ! # Override the wrapping code to igore the special sequences. sub wrap { my $self = shift; local $_ = shift; my $output = ''; my $spaces = ' ' x $$self{MARGIN}; my $width = $$self{width} - $$self{MARGIN}; ! my $code = "(?:\Q$$self{BOLD}\E|\Q$$self{UNDL}\E|\Q$$self{NORM}\E)"; ! while (length > $width) { ! if (s/^((?:$code?[^\n]){0,$width})\s+// ! || s/^((?:$code?[^\n]){$width})//) { ! $output .= $spaces . $1 . "\n"; ! } else { ! last; ! } } $output .= $spaces . $_; $output =~ s/\s+$/\n\n/; $output; } ############################################################################## # Module return value and documentation --- 97,133 ---- $self->output ($$self{BOLD} . $code . $$self{NORM}); } ! # Override the wrapping code to ignore the special sequences. sub wrap { my $self = shift; local $_ = shift; my $output = ''; my $spaces = ' ' x $$self{MARGIN}; my $width = $$self{width} - $$self{MARGIN}; ! my $invisible = "\Q$$self{BOLD}\E|\Q$$self{UNDL}\E|\Q$$self{NORM}\E"; ! my $code = "(?:$invisible)"; ! my $length = visible_length($_, $invisible); ! while ($length > $width) { ! if (s/^((?:$code?[^\n]){0,$width})\s+// ! || s/^((?:$code?[^\n]){$width})//) { ! $output .= $spaces . $1 . "\n"; ! $length = visible_length($_, $invisible); ! } else { ! last; ! } } $output .= $spaces . $_; $output =~ s/\s+$/\n\n/; $output; } + sub visible_length { + my ($text, $invisible) = @_; + my $sum = 0; + while ($text =~ /$invisible/g) { $sum += length($&); } + length($text) - $sum; + } + ############################################################################## # Module return value and documentation
Thanks! I'll look at this for the next version.
[RRA - Mon Jun 21 18:46:58 2004]: Show quoted text
> Thanks! I'll look at this for the next version.
I've looked at your patch to add a separate length function for Pod::Text::Termcap, and after studying it for a bit, I don't believe it's necessary. Yes, the length metric isn't accurate, but it's only there to prevent an unnecessary final pass through the while loop which is harmless if taken (the last line will just be picked up by the regex rather than appended to output at the end). I did, however, find a different bug that was causing the wrap function to miscount length when there were multiple escape sequences in a row, and that bug will be fixed in the next release (which is waiting on a Pod::Parser release).
Fixed in podlators 2.00, just released.