Skip Menu |

This queue is for tickets about the Text-RecordParser CPAN distribution.

Report information
The Basics
Id: 38871
Status: resolved
Worked: 20 min
Priority: 0/
Queue: Text-RecordParser

People
Owner: kclark [...] cpan.org
Requestors: mike [...] mikebaas.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: v1.2.1
Fixed in: (no value)



Subject: trim should not trim trailing whitespace on a line
The 'trim' method gets a little overzealous and trims trailing and leading spaces from lines. If the last field in a line is a blank, it will remove this field. 'trim' should only trim each individual field, no need to trim the line itself. Attached is a .diff that fixes this problem.
Subject: trim.diff
--- /usr/local/lib/perl5/site_perl/5.10.0/Text/RecordParser.pm 2008-08-30 17:01:08.000000000 -0700 +++ RecordParser.pm 2006-05-18 13:35:22.000000000 -0700 @@ -445,6 +445,7 @@ defined( $line = <$fh> ) or return; chomp $line; next if $comment and $line =~ $comment; + $line =~ s/^\s+|\s+$//g if $self->trim; last if $line; } @@ -465,8 +466,7 @@ } if ( $self->trim ) { - @fields = map { defined $_ && s/^\s+|\s+$//g; $_ } @fields; - + @fields = map { s/^\s+|\s+$//g; $_ } @fields; } while ( my ( $position, $callback ) = each %{ $self->field_compute } ) { @@ -571,7 +571,6 @@ =cut my $self = shift; - my %args = defined $_[0] && ref $_[0] eq 'HASH' ? %{ shift() } : @_ % 2 == 0 ? @_
On Sat Aug 30 20:13:54 2008, MBAAS wrote: Show quoted text
> The 'trim' method gets a little overzealous and trims trailing and > leading spaces from lines. If the last field in a line is a blank, it > will remove this field. 'trim' should only trim each individual field, > no need to trim the line itself. Attached is a .diff that fixes this > problem.
The first attached diff is wrong. This is the correct patch. Thanks.
--- RecordParser.pm 2006-05-18 13:35:22.000000000 -0700 +++ /usr/local/lib/perl5/site_perl/5.10.0/Text/RecordParser.pm 2008-08-30 17:01:08.000000000 -0700 @@ -445,7 +445,6 @@ defined( $line = <$fh> ) or return; chomp $line; next if $comment and $line =~ $comment; - $line =~ s/^\s+|\s+$//g if $self->trim; last if $line; } @@ -466,7 +465,8 @@ } if ( $self->trim ) { - @fields = map { s/^\s+|\s+$//g; $_ } @fields; + @fields = map { defined $_ && s/^\s+|\s+$//g; $_ } @fields; + } while ( my ( $position, $callback ) = each %{ $self->field_compute } ) { @@ -571,6 +571,7 @@ =cut my $self = shift; + my %args = defined $_[0] && ref $_[0] eq 'HASH' ? %{ shift() } : @_ % 2 == 0 ? @_
The previously attached .diff fixes this issue.
Accepted. Will be included in 1.3.0.