Skip to content

Commit

Permalink
Import of HMBRAND/Text-CSV_XS-0.58 from CPAN.
Browse files Browse the repository at this point in the history
gitpan-cpan-distribution: Text-CSV_XS
gitpan-cpan-version:      0.58
gitpan-cpan-path:         HMBRAND/Text-CSV_XS-0.58.tgz
gitpan-cpan-author:       HMBRAND
gitpan-cpan-maturity:     released
  • Loading branch information
H.Merijn Brand authored and Gitpan committed Oct 22, 2014
1 parent 9aac0f6 commit 21d4f7b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CSV_XS.pm
Expand Up @@ -30,7 +30,7 @@ use DynaLoader ();
use Carp;

use vars qw( $VERSION @ISA );
$VERSION = "0.57";
$VERSION = "0.58";
@ISA = qw( DynaLoader );
bootstrap Text::CSV_XS $VERSION;

Expand Down
4 changes: 2 additions & 2 deletions CSV_XS.xs
Expand Up @@ -933,10 +933,10 @@ restart:
}

#if ALLOW_ALLOW
if (csv->allow_loose_quotes && csv->escape_char != csv->quote_char) {
if (csv->allow_loose_escapes && csv->escape_char == csv->quote_char) {
CSV_PUT_SV (c);
c = c2;
/* uncovered */ goto restart;
goto restart;
}
#endif

Expand Down
6 changes: 6 additions & 0 deletions ChangeLog
@@ -1,3 +1,9 @@
2008-10-30 0.58 - H.Merijn Brand <h.m.brand@xs4all.nl>

* Small typo in test message (RT#40410, JPL)
* Parse error test on "\0 (RT#40507)
* Fixed allow_loose_escapes bug disclosed by RT#40507

2008-10-21 0.57 - H.Merijn Brand <h.m.brand@xs4all.nl>

* Don't bootstrap twice. Don't know how/when it came in there
Expand Down
4 changes: 2 additions & 2 deletions META.yml
@@ -1,6 +1,6 @@
--- #YAML:1.1
name: Text-CSV_XS
version: 0.57
version: 0.58
abstract: Comma-Separated Values manipulation routines
license: perl
author:
Expand All @@ -10,7 +10,7 @@ distribution_type: module
provides:
Text::CSV_XS:
file: CSV_XS.pm
version: 0.57
version: 0.58
requires:
perl: 5.005
DynaLoader: 0
Expand Down
2 changes: 1 addition & 1 deletion t/01_pod.t
Expand Up @@ -6,5 +6,5 @@ $^W = 1;
use Test::More;

eval "use Test::Pod::Coverage tests => 1";
plan skip_all => "Test::Pod::Covarage required for testing POD Coverage" if $@;
plan skip_all => "Test::Pod::Coverage required for testing POD Coverage" if $@;
pod_coverage_ok ("Text::CSV_XS", "Text::CSV_XS is covered");
65 changes: 48 additions & 17 deletions t/70_rt.t
Expand Up @@ -4,7 +4,7 @@ use strict;
$^W = 1;

#use Test::More "no_plan";
use Test::More tests => 73;
use Test::More tests => 80;

BEGIN {
use_ok "Text::CSV_XS", ();
Expand All @@ -14,24 +14,27 @@ BEGIN {
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

{ # http://rt.cpan.org/Ticket/Display.html?id=24386
# #24386: \t doesn't work in _XS, works in _PP

my @lines = @{$input{24386}};
$rt = 24386;
my @lines = @{$input{$rt}};

ok (my $csv = Text::CSV_XS->new ({ sep_char => "\t" }), "RT-24386: \\t doesn't work");
ok (my $csv = Text::CSV_XS->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");
Expand All @@ -44,10 +47,11 @@ while (<DATA>) {
{ # 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}};
print FH @{$input{$rt}};
close FH;
ok (my $csv = Text::CSV_XS->new ({ binary => 1 }), "RT-21530: getline () return at eof");
ok (my $csv = Text::CSV_XS->new ({ binary => 1 }), "RT-$rt: $desc{$rt}");
open FH, "<$csv_file";
my $row;
foreach my $line (1 .. 5) {
Expand All @@ -63,28 +67,30 @@ while (<DATA>) {

{ # 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_XS->new ({ quote_char => "~" }), "RT-18703: Fails to use quote_char of '~'");
ok ($csv = Text::CSV_XS->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_XS->new ({
sep_char => ";",
escape_char => "\\",
allow_loose_escapes => 1,
}), "RT-15076: escape chars ....");
}), "RT-$rt: $desc{$rt}");

ok ($csv->parse ($input{15076}[0]), "Line 1");
ok (@fld = $csv->fields, "Fields");
Expand All @@ -95,10 +101,11 @@ while (<DATA>) {

{ # 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}};
print FH @{$input{$rt}};
close FH;
ok (my $csv = Text::CSV_XS->new (), "RT-34474: getline_hr ()");
ok (my $csv = Text::CSV_XS->new (), "RT-$rt: $desc{$rt}");
is ($csv->column_names, undef, "No headers yet");
open FH, "<$csv_file";
my $row;
Expand All @@ -118,12 +125,13 @@ while (<DATA>) {

{ # 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_XS->new (), "RT-38960: print () fails");
ok (my $csv = Text::CSV_XS->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");
Expand All @@ -132,6 +140,25 @@ while (<DATA>) {
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_XS->new ({ binary => 1 }), "RT-$rt: $desc{$rt}");
my $str = $input{40507}[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{40507}[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");
$csv->allow_loose_escapes (1);
ok ($csv->parse ($str), "parse () badly escaped NULL");
}

__END__
«24386» - \t doesn't work in _XS, works in _PP
VIN StockNumber Year Make Model MD Engine EngineSize Transmission DriveTrain Trim BodyStyle CityFuel HWYFuel Mileage Color InteriorColor InternetPrice RetailPrice Notes ShortReview Certified NewUsed Image_URLs Equipment
Expand All @@ -157,3 +184,7 @@ code,name,price,description
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"

0 comments on commit 21d4f7b

Please sign in to comment.