r32403 - in /branches/upstream/libtext-csv-perl/current: Changes META.yml Makefile.PL README lib/Text/CSV.pm lib/Text/CSV_PP.pm t/70_rt.t
ansgar-guest at users.alioth.debian.org
ansgar-guest at users.alioth.debian.org
Sun Mar 29 18:20:02 UTC 2009
Author: ansgar-guest
Date: Sun Mar 29 18:19:55 2009
New Revision: 32403
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=32403
Log:
[svn-upgrade] Integrating new upstream version, libtext-csv-perl (1.11)
Modified:
branches/upstream/libtext-csv-perl/current/Changes
branches/upstream/libtext-csv-perl/current/META.yml
branches/upstream/libtext-csv-perl/current/Makefile.PL
branches/upstream/libtext-csv-perl/current/README
branches/upstream/libtext-csv-perl/current/lib/Text/CSV.pm
branches/upstream/libtext-csv-perl/current/lib/Text/CSV_PP.pm
branches/upstream/libtext-csv-perl/current/t/70_rt.t
Modified: branches/upstream/libtext-csv-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-csv-perl/current/Changes?rev=32403&op=diff
==============================================================================
--- branches/upstream/libtext-csv-perl/current/Changes (original)
+++ branches/upstream/libtext-csv-perl/current/Changes Sun Mar 29 18:19:55 2009
@@ -1,4 +1,10 @@
Revision history for Perl extension Text::CSV.
+
+1.11 Sat Mar 21 16:07:29 2009
+ - updated the compatibility for Text::CSV_XS version 0.63
+ * added error 1002
+ - updated the compatibility for Text::CSV_XS version 0.58
+ * fixed allow_loose_escapes bug
1.10 Wed Oct 22 02:34:03 2008
- updated the compatibility for Text::CSV_XS version 0.56
Modified: branches/upstream/libtext-csv-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-csv-perl/current/META.yml?rev=32403&op=diff
==============================================================================
--- branches/upstream/libtext-csv-perl/current/META.yml (original)
+++ branches/upstream/libtext-csv-perl/current/META.yml Sun Mar 29 18:19:55 2009
@@ -1,8 +1,8 @@
--- #YAML:1.0
name: Text-CSV
-version: 1.10
+version: 1.11
abstract: comma-separated values manipulator (using XS or PurePerl)
-license: ~
+license: perl
author:
- Makamaka Hannyaharamitu, E<lt>makamaka[at]cpan.orgE<gt>
generated_by: ExtUtils::MakeMaker version 6.42
Modified: branches/upstream/libtext-csv-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-csv-perl/current/Makefile.PL?rev=32403&op=diff
==============================================================================
--- branches/upstream/libtext-csv-perl/current/Makefile.PL (original)
+++ branches/upstream/libtext-csv-perl/current/Makefile.PL Sun Mar 29 18:19:55 2009
@@ -60,4 +60,5 @@
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'lib/Text/CSV.pm', # retrieve abstract from module
AUTHOR => 'Makamaka Hannyaharamitu, E<lt>makamaka[at]cpan.orgE<gt>') : ()),
+ ( $ExtUtils::MakeMaker::VERSION >= 6.3002 ? ('LICENSE' => 'perl', ) : () ),
);
Modified: branches/upstream/libtext-csv-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-csv-perl/current/README?rev=32403&op=diff
==============================================================================
--- branches/upstream/libtext-csv-perl/current/README (original)
+++ branches/upstream/libtext-csv-perl/current/README Sun Mar 29 18:19:55 2009
@@ -1,4 +1,4 @@
-Text::CSV version 1.10
+Text::CSV version 1.11
========================
comma-separated values manipulator
Modified: branches/upstream/libtext-csv-perl/current/lib/Text/CSV.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-csv-perl/current/lib/Text/CSV.pm?rev=32403&op=diff
==============================================================================
--- branches/upstream/libtext-csv-perl/current/lib/Text/CSV.pm (original)
+++ branches/upstream/libtext-csv-perl/current/lib/Text/CSV.pm Sun Mar 29 18:19:55 2009
@@ -5,14 +5,14 @@
use Carp ();
BEGIN {
- $Text::CSV::VERSION = '1.10';
+ $Text::CSV::VERSION = '1.11';
$Text::CSV::DEBUG = 0;
}
# if use CSV_XS, requires version
my $Module_XS = 'Text::CSV_XS';
my $Module_PP = 'Text::CSV_PP';
-my $XS_Version = '0.56';
+my $XS_Version = '0.63';
my $Is_Dynamic = 0;
@@ -270,9 +270,9 @@
=head1 VERSION
- 1.10
-
-This module is compatible with Text::CSV_XS B<0.56> or later.
+ 1.11
+
+This module is compatible with Text::CSV_XS B<0.63> and later.
=head2 BINARY MODE
@@ -361,12 +361,14 @@
=item allow_whitespace
When this option is set to true, whitespace (TAB's and SPACE's)
-surrounding the separation character is removed when parsing. So
-lines like:
+surrounding the separation character is removed when parsing. If
+either TAB or SPACE is one of the three major characters C<sep_char>,
+C<quote_char>, or C<escape_char> it will not be considered whitespace.
1 , "foo" , bar , 3 , zapp
are now correctly parsed, even though it violates the CSV specs.
+
Note that B<all> whitespace is stripped from start and end of each
field. That would make is more a I<feature> than a way to be able
to parse bad CSV lines, as
@@ -984,17 +986,17 @@
Text::CSV
Copyright (C) 1997 Alan Citterman. All rights reserved.
-Copyright (C) 2007-2008 Makamaka Hannyaharamitu.
+Copyright (C) 2007-2009 Makamaka Hannyaharamitu.
Text::CSV_PP:
-Copyright (C) 2005-2008 Makamaka Hannyaharamitu.
+Copyright (C) 2005-2009 Makamaka Hannyaharamitu.
Text:CSV_XS:
-Copyright (C) 2007-2008 H.Merijn Brand for PROCURA B.V.
+Copyright (C) 2007-2009 H.Merijn Brand for PROCURA B.V.
Copyright (C) 1998-2001 Jochen Wiedmann. All rights reserved.
Portions Copyright (C) 1997 Alan Citterman. All rights reserved.
Modified: branches/upstream/libtext-csv-perl/current/lib/Text/CSV_PP.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-csv-perl/current/lib/Text/CSV_PP.pm?rev=32403&op=diff
==============================================================================
--- branches/upstream/libtext-csv-perl/current/lib/Text/CSV_PP.pm (original)
+++ branches/upstream/libtext-csv-perl/current/lib/Text/CSV_PP.pm Sun Mar 29 18:19:55 2009
@@ -11,7 +11,7 @@
use vars qw($VERSION);
use Carp ();
-$VERSION = '1.18';
+$VERSION = '1.19';
sub PV { 0 }
sub IV { 1 }
@@ -25,6 +25,7 @@
# PP and XS
1000 => "INI - constructor failed",
1001 => "sep_char is equal to quote_char or escape_char",
+ 1002 => "INI - allow_whitespace with escape_char or quote_char SP or TAB",
2010 => "ECR - QUO char inside quotes followed by CR not part of EOL",
2011 => "ECR - Characters after end of quoted field",
@@ -149,6 +150,16 @@
}
$self->{$prop} = $attr->{$prop};
}
+
+ if ( $self->{allow_whitespace} and
+ ( defined $self->{quote_char} && $self->{quote_char} =~ m/^[ \t]$/ )
+ ||
+ ( defined $self->{escape_char} && $self->{escape_char} =~ m/^[ \t]$/ )
+ ) {
+ $last_new_error = "INI - allow_whitespace with escape_char or quote_char SP or TAB";
+ return;
+ }
+
$last_new_error = '';
@@ -381,6 +392,35 @@
if ($col =~ $re_quoted) {
$flag |= IS_QUOTED if ($keep_meta_info);
$col = $1;
+
+ my $flga_in_quot_esp;
+ while ( $col =~ /$re_in_quot_esp1/g ) {
+ my $str = $1;
+ $flga_in_quot_esp = 1;
+
+ if ($str !~ $re_in_quot_esp2) {
+ unless ($self->{allow_loose_escapes}) {
+ $self->_set_error_diag( 2025, $pos - 2 ); # Needless ESC in quoted field
+ $palatable = 0;
+ last;
+ }
+ else {
+ $col =~ s/\Q$esc\E(.)/$1/g;
+ }
+ }
+
+ }
+
+ last unless ( $palatable );
+
+ unless ( $flga_in_quot_esp ) {
+ if ($col =~ /(?<!\Q$esc\E)\Q$esc\E/) {
+ $self->_set_error_diag( 4002, $pos - 1 ); # No escaped ESC in quoted field
+ $palatable = 0;
+ last;
+ }
+ }
+=pod
if ($col =~ $re_in_quot_esp1) {
my $str = $1;
@@ -403,6 +443,8 @@
}
}
+=cut
+
$col =~ s{$re_esc}{$1 eq '0' ? "\0" : $1}eg;
if ($types and $types->[$i]) { # IV or NV
@@ -730,7 +772,7 @@
################################################################################
BEGIN {
- for my $method (qw/quote_char escape_char sep_char always_quote binary allow_whitespace
+ for my $method (qw/sep_char always_quote binary
keep_meta_info allow_loose_quotes allow_loose_escapes verbatim blank_is_undef/) {
eval qq|
sub $method {
@@ -739,6 +781,42 @@
}
|;
}
+}
+
+
+sub quote_char {
+ my $self = shift;
+ if ( @_ ) {
+ my $qc = shift;
+ defined $qc && $qc =~ m/^[ \t]$/ && $self->{allow_whitespace} and Carp::croak( $self->SetDiag(1002) );
+ $self->{quote_char} = $qc;
+ }
+ $self->{quote_char};
+}
+
+
+sub escape_char {
+ my $self = shift;
+ if ( @_ ) {
+ my $es = shift;
+ defined $es && $es =~ m/^[ \t]$/ && $self->{allow_whitespace} and Carp::croak( $self->SetDiag(1002) );
+ $self->{escape_char} = $es;
+ }
+ $self->{escape_char};
+}
+
+
+sub allow_whitespace {
+ my $self = shift;
+ if ( @_ ) {
+ my $aw = shift;
+ $aw and
+ (defined $self->{quote_char} && $self->{quote_char} =~ m/^[ \t]$/) ||
+ (defined $self->{escape_char} && $self->{escape_char} =~ m/^[ \t]$/)
+ and Carp::croak ($self->SetDiag (1002));
+ $self->{allow_whitespace} = $aw;
+ }
+ $self->{allow_whitespace};
}
@@ -882,12 +960,16 @@
=item allow_whitespace
When this option is set to true, whitespace (TAB's and SPACE's)
-surrounding the separation character is removed when parsing. So
-lines like:
+surrounding the separation character is removed when parsing. If
+either TAB or SPACE is one of the three major characters C<sep_char>,
+C<quote_char>, or C<escape_char> it will not be considered whitespace.
+
+So lines like:
1 , "foo" , bar , 3 , zapp
are now correctly parsed, even though it violates the CSV specs.
+
Note that B<all> whitespace is stripped from start and end of each
field. That would make is more a I<feature> than a way to be able
to parse bad CSV lines, as
@@ -1378,6 +1460,11 @@
The separation character cannot be equal to either the quotation character
or the escape character, as that will invalidate all parsing rules.
+=item 1002 "INI - allow_whitespace with escape_char or quote_char SP or TAB"
+
+Using C<allow_whitespace> when either C<escape_char> or C<quote_char> is
+equal to SPACE or TAB is too ambiguous to allow.
+
=item 2010 "ECR - QUO char inside quotes followed by CR not part of EOL"
=item 2011 "ECR - Characters after end of quoted field"
@@ -1440,7 +1527,7 @@
=head1 COPYRIGHT AND LICENSE
-Copyright 2005-2008 by Makamaka Hannyaharamitu, E<lt>makamaka[at]cpan.orgE<gt>
+Copyright 2005-2009 by Makamaka Hannyaharamitu, E<lt>makamaka[at]cpan.orgE<gt>
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Modified: branches/upstream/libtext-csv-perl/current/t/70_rt.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-csv-perl/current/t/70_rt.t?rev=32403&op=diff
==============================================================================
--- branches/upstream/libtext-csv-perl/current/t/70_rt.t (original)
+++ branches/upstream/libtext-csv-perl/current/t/70_rt.t Sun Mar 29 18:19:55 2009
@@ -3,11 +3,13 @@
use strict;
$^W = 1;
+BEGIN { $ENV{PERL_TEXT_CSV} = 0; }
+
+
#use Test::More "no_plan";
- use Test::More tests => 73;
+ use Test::More tests => 367;
BEGIN {
- $ENV{PERL_TEXT_CSV} = 0;
use_ok "Text::CSV", ();
plan skip_all => "Cannot load Text::CSV" if $@;
}
@@ -15,14 +17,16 @@
my $csv_file = "_test.csv";
END { unlink $csv_file }
-my $rt_no;
-my %input;
+my ($rt, %input, %desc);
while (<DATA>) {
- if (m/^«(\d+)»/) {
- $rt_no = $1;
+ if (s/^«(\d+)»\s*-?\s*//) {
+ chomp;
+ $rt = $1;
+ $desc{$rt} = $_;
next;
}
- push @{$input{$rt_no}}, $_;
+ s/\\([0-7]{1,3})/chr oct $1/ge;
+ push @{$input{$rt}}, $_;
}
# Regression Tests based on RT reports
@@ -30,9 +34,10 @@
{ # http://rt.cpan.org/Ticket/Display.html?id=24386
# #24386: \t doesn't work in _XS, works in _PP
- my @lines = @{$input{24386}};
-
- ok (my $csv = Text::CSV->new ({ sep_char => "\t" }), "RT-24386: \\t doesn't work");
+ $rt = 24386;
+ my @lines = @{$input{$rt}};
+
+ ok (my $csv = Text::CSV->new ({ sep_char => "\t" }), "RT-$rt: $desc{$rt}");
is ($csv->sep_char, "\t", "sep_char = TAB");
foreach my $line (0 .. $#lines) {
ok ($csv->parse ($lines[$line]), "parse line $line");
@@ -45,10 +50,11 @@
{ # http://rt.cpan.org/Ticket/Display.html?id=21530
# 21530: getline () does not return documented value at end of filehandle
# IO::Handle was first released with perl 5.00307
+ $rt = 21530;
open FH, ">$csv_file";
- print FH @{$input{21530}};
- close FH;
- ok (my $csv = Text::CSV->new ({ binary => 1 }), "RT-21530: getline () return at eof");
+ print FH @{$input{$rt}};
+ close FH;
+ ok (my $csv = Text::CSV->new ({ binary => 1 }), "RT-$rt: $desc{$rt}");
open FH, "<$csv_file";
my $row;
foreach my $line (1 .. 5) {
@@ -64,30 +70,32 @@
{ # http://rt.cpan.org/Ticket/Display.html?id=21530
# 18703: Fails to use quote_char of '~'
+ $rt = 18703;
my ($csv, @fld);
- ok ($csv = Text::CSV->new ({ quote_char => "~" }), "RT-18703: Fails to use quote_char of '~'");
+ ok ($csv = Text::CSV->new ({ quote_char => "~" }), "RT-$rt: $desc{$rt}");
is ($csv->quote_char, "~", "quote_char is '~'");
- ok ($csv->parse ($input{18703}[0]), "Line 1");
+ ok ($csv->parse ($input{$rt}[0]), "Line 1");
ok (@fld = $csv->fields, "Fields");
is (scalar @fld, 1, "Line 1 has only one field");
is ($fld[0], "Style Name", "Content line 1");
# The line has invalid escape. the escape should only be
# used for the special characters
- ok (!$csv->parse ($input{18703}[1]), "Line 2");
+ ok (!$csv->parse ($input{$rt}[1]), "Line 2");
}
{ # http://rt.cpan.org/Ticket/Display.html?id=15076
# 15076: escape_char before characters that do not need to be escaped.
+ $rt = 15076;
my ($csv, @fld);
ok ($csv = Text::CSV->new ({
sep_char => ";",
escape_char => "\\",
allow_loose_escapes => 1,
- }), "RT-15076: escape chars ....");
-
- ok ($csv->parse ($input{15076}[0]), "Line 1");
+ }), "RT-$rt: $desc{$rt}");
+
+ ok ($csv->parse ($input{$rt}[0]), "Line 1");
ok (@fld = $csv->fields, "Fields");
is (scalar @fld, 2, "Line 1 has two fields");
is ($fld[0], "Example", "Content field 1");
@@ -96,10 +104,11 @@
{ # http://rt.cpan.org/Ticket/Display.html?id=34474
# 34474: wish: integrate row-as-hashref feature from Parse::CSV
+ $rt = 34474;
open FH, ">$csv_file";
- print FH @{$input{34474}};
- close FH;
- ok (my $csv = Text::CSV->new (), "RT-34474: getline_hr ()");
+ print FH @{$input{$rt}};
+ close FH;
+ ok (my $csv = Text::CSV->new (), "RT-$rt: $desc{$rt}");
is ($csv->column_names, undef, "No headers yet");
open FH, "<$csv_file";
my $row;
@@ -119,19 +128,133 @@
{ # http://rt.cpan.org/Ticket/Display.html?id=38960
# 38960: print () on invalid filehandle warns and returns success
+ $rt = 38960;
open FH, ">$csv_file";
print FH "";
close FH;
my $err = "";
open FH, "<$csv_file";
- ok (my $csv = Text::CSV->new (), "RT-38960: print () fails");
+ ok (my $csv = Text::CSV->new (), "RT-$rt: $desc{$rt}");
local $SIG{__WARN__} = sub { $err = "Warning" };
ok (!$csv->print (*FH, [ 1 .. 4 ]), "print ()");
is ($err, "Warning", "IO::Handle triggered a warning");
- my @err = $csv->error_diag ();
- is ($err[0], 2200, "error 2200");
+ is (($csv->error_diag)[0], 2200, "error 2200");
close FH;
unlink $csv_file;
+ }
+
+{ # http://rt.cpan.org/Ticket/Display.html?id=40507
+ # 40507: Parsing fails on escaped null byte
+ $rt = 40507;
+ ok (my $csv = Text::CSV->new ({ binary => 1 }), "RT-$rt: $desc{$rt}");
+ my $str = $input{$rt}[0];
+ ok ($csv->parse ($str), "parse () correctly escaped NULL");
+ is_deeply ([ $csv->fields ],
+ [ qq{Audit active: "TRUE \0},
+ qq{Desired:},
+ qq{Audit active: "TRUE \0} ], "fields ()");
+ $str = $input{$rt}[1];
+ is ($csv->parse ($str), 0, "parse () badly escaped NULL");
+ my @diag = $csv->error_diag;
+# is ($diag[0], 2023, "Error 2023");
+# is ($diag[2], 23, "Position 23");
+ is ($diag[0], 2025, "Error 2025 but 2023 in XS");
+ is ($diag[2], 24, "Position 24 but 23 in XS");
+ $csv->allow_loose_escapes (1);
+ ok ($csv->parse ($str), "parse () badly escaped NULL");
+ }
+
+{ # http://rt.cpan.org/Ticket/Display.html?id=42642
+ # 42642: failure on unusual quote/sep values
+ $rt = 42642;
+ SKIP: {
+ $] < 5.008002 and skip "UTF8 unreliable in perl $]", 6;
+
+ open FH, ">$csv_file";
+ print FH @{$input{$rt}};
+ close FH;
+ my ($sep, $quo) = ("\x14", "\xfe");
+ chop ($_ = "$_\x{20ac}") for $sep, $quo;
+ ok (my $csv = Text::CSV->new ({ binary => 1, sep_char => $sep }), "RT-$rt: $desc{$rt}");
+ ok ($csv->quote_char ($quo), "Set quote_char");
+ open FH, "<$csv_file";
+ ok (my $row = $csv->getline (*FH), "getline () with decode sep/quo");
+ $csv->error_diag ();
+ close FH;
+ unlink $csv_file;
+ is_deeply ($row, [qw( DOG CAT WOMBAT BANDERSNATCH )], "fields ()");
+ ok ($csv->parse ($input{$rt}[1]), "parse () with decoded sep/quo");
+ is_deeply ([ $csv->fields ], [ 0..3 ], "fields ()");
+ }
+ }
+
+{ # http://rt.cpan.org/Ticket/Display.html?id=43927
+ # 43927: Is bind_columns broken or am I using it wrong?
+ $rt = 43927;
+ SKIP: {
+ open FH, ">$csv_file";
+ print FH @{$input{$rt}};
+ close FH;
+ my ($c1, $c2);
+ ok (my $csv = Text::CSV->new ({ binary => 1 }), "RT-$rt: $desc{$rt}");
+ ok ($csv->bind_columns (\$c1, \$c2), "bind columns");
+ open FH, "<$csv_file";
+ ok (my $row = $csv->getline (*FH), "getline () with bound columns");
+ $csv->error_diag ();
+ close FH;
+ unlink $csv_file;
+ is_deeply ($row, [], "should return empty ref");
+ is_deeply ([ $c1, $c2], [ 1, 2 ], "fields ()");
+ }
+ }
+
+{ # http://rt.cpan.org/Ticket/Display.html?id=44402
+ # 44402 - Unexpected results parsing tab-separated spaces
+ $rt = 44402;
+ SKIP: {
+ open FH, ">$csv_file";
+ my @ws = ("", " ", " ");
+ foreach my $f1 (@ws) {
+ foreach my $f2 (@ws) {
+ foreach my $f3 (@ws) {
+ print FH "$f1\t$f2\t$f3\r\n";
+ }
+ }
+ }
+ close FH;
+
+ my $csv;
+ ok ($csv = Text::CSV->new ({
+ sep_char => "\t",
+ }), "RT-$rt: $desc{$rt}");
+ open FH, "<$csv_file";
+ while (my $row = $csv->getline (*FH)) {
+ ok ($row, "getline $.");
+ my @row = @$row;
+ is ($#row, 2, "Got 3 fields");
+ like ($row[$_], qr{^ *$}, "field $_ with only spaces") for 0..2;
+ }
+ ok ($csv->eof, "read complete file");
+ close FH;
+
+ ok ($csv = Text::CSV->new ({
+ sep_char => "\t",
+ allow_whitespace => 1,
+ }), "RT-$rt: $desc{$rt}");
+ open FH, "<$csv_file";
+ while (my $row = $csv->getline (*FH)) {
+ ok ($row, "getline $.");
+ my @row = @$row;
+ is ($#row, 2, "Got 3 fields");
+ is ($row[$_], "", "field $_ empty") for 0..2;
+ }
+ ok ($csv->eof, "read complete file");
+ close FH;
+ unlink $csv_file;
+
+ ok ($csv->parse (" \t \t "), "parse ()");
+ is_deeply ([$csv->fields],["","",""],"3 empty fields");
+ }
}
__END__
@@ -159,3 +282,13 @@
1,Dress,240.00,"Evening gown"
2,Drinks,82.78,"Drinks"
3,Sex,-9999.99,"Priceless"
+«38960» - print () on invalid filehandle warns and returns success
+«40507» - Parsing fails on escaped null byte
+"Audit active: ""TRUE "0","Desired:","Audit active: ""TRUE "0"
+"Audit active: ""TRUE "\0","Desired:","Audit active: ""TRUE "\0"
+«42642» - failure on unusual quote/sep values
+þDOGþþCATþþWOMBATþþBANDERSNATCHþ
+þ0þþ1þþ2þþ3þ
+«43927» - Is bind_columns broken or am I using it wrong?
+1,2
+«44402» - Unexpected results parsing tab-separated spaces
More information about the Pkg-perl-cvs-commits
mailing list