diff -Naur ./Text-CSV_XS-0.23/CSV_XS.pm ./Text-CSV_XS/CSV_XS.pm --- ./Text-CSV_XS-0.23/CSV_XS.pm 2001-10-10 03:11:59.000000000 -0400 +++ ./Text-CSV_XS/CSV_XS.pm 2006-10-29 00:48:51.000000000 -0400 @@ -567,6 +567,13 @@ A CSV string may be terminated by 0x0A (line feed) or by 0x0D,0x0A (carriage return, line feed). +=item 6 + +A field within CSV must be surrounded by double-quotes to contain a +line-ending sequence (0x0A or 0x0D,0x0A). + +=back + =head1 AUTHOR Alan Citterman Falan@mfgrtl.comE> wrote the original Perl diff -Naur ./Text-CSV_XS-0.23/CSV_XS.xs ./Text-CSV_XS/CSV_XS.xs --- ./Text-CSV_XS-0.23/CSV_XS.xs 2001-10-10 03:09:10.000000000 -0400 +++ ./Text-CSV_XS/CSV_XS.xs 2006-10-29 00:50:55.000000000 -0400 @@ -310,6 +310,13 @@ insideField = newSVpv("", 0); waitingForField = 0; goto restart; + } else if (csv->binary) { + /* allow raw \015's at the start of binary fields, quotes or no */ + insideField = newSVpv("", 0); + CSV_PUT_SV(insideField, c); + c = c2; + waitingForField = 0; + goto restart; } else if (c2 == '\012') { c = '\012'; goto restart; @@ -329,6 +336,11 @@ if (c2 == '\012') { AV_PUSH(fields, insideField); return TRUE; + } else if (csv->binary) { + /* allow raw \015's inside binary fields, quotes or no */ + CSV_PUT_SV(insideField, c); + c = c2; + goto restart; } else { ERROR_INSIDE_FIELD; } diff -Naur ./Text-CSV_XS-0.23/Makefile.PL ./Text-CSV_XS/Makefile.PL --- ./Text-CSV_XS-0.23/Makefile.PL 1999-06-28 05:02:16.000000000 -0400 +++ ./Text-CSV_XS/Makefile.PL 2006-10-29 00:40:46.000000000 -0400 @@ -28,5 +28,6 @@ 'dist' => { 'SUFFIX' => ".gz", 'DIST_DEFAULT' => 'all tardist', 'COMPRESS' => "gzip -9f" }, - 'DEFINE' => $def + 'DEFINE' => $def, + 'PREREQ_PM' => { 'Test::More' => 0 }, ); diff -Naur ./Text-CSV_XS-0.23/t/mac.t ./Text-CSV_XS/t/mac.t --- ./Text-CSV_XS-0.23/t/mac.t 1969-12-31 19:00:00.000000000 -0500 +++ ./Text-CSV_XS/t/mac.t 2006-10-29 00:52:41.000000000 -0400 @@ -0,0 +1,57 @@ +# -*- perl -w -*- + +# +# Test Mac line-endings (\015) as part of a field in binary mode. In +# prior versions this didn't work due to the special handling of \015 +# to support windows line-endings automatically. +# + +require 5.004; +use strict; + +use Text::CSV_XS; +use Test::More qw(no_plan); + +# format a string for display after failing tests +sub Display { + my $string = shift; + $string =~ s!([^-\w "',])!"\\0" . sprintf("%lo", ord($1))!eg; + return $string; +} + +my @lines; +my @fields; + +$lines[0] = qq("a","line","with","embedded \015 mac line-endings"\n); +$fields[0] = ["a","line","with","embedded \015 mac line-endings"]; + +$lines[1] = qq(a,line,with,embedded unquoted \015 mac line-endings\n); +$fields[1] = ["a","line","with","embedded unquoted \015 mac line-endings"]; + +# make sure \012\015 comes through unmolested in binary mode +$lines[2] = qq(a,line,with,"embedded \015\012 windows line-endings"\n); +$fields[2] = ["a","line","with","embedded \015\012 windows line-endings"]; + +$lines[3] = qq(a,field,with,"\015 mac line-endings at the start"\n); +$fields[3] = ["a","field","with","\015 mac line-endings at the start"]; + +$lines[4] = qq("\015 mac line-endings at the start of a line"\n); +$fields[4] = ["\015 mac line-endings at the start of a line"]; + +$lines[5] = qq("mac line-endings at the end of a line\015"\n); +$fields[5] = ["mac line-endings at the end of a line\015"]; + +$lines[6] = qq(mac line-endings at the end of a line unquoted\015\n); +$fields[6] = ["mac line-endings at the end of a line unquoted"]; + +$lines[7] = qq(make,sure,windows,line-endings,work\015\012right\015\012); +$fields[7] = ["make","sure","windows","line-endings","work"]; + +my $csv = Text::CSV_XS->new({ binary => 1}); + +foreach my $i (0 .. $#lines) { + ok($csv->parse($lines[$i]), "parse test for $i") + or print STDERR "\n# Failed to parse: " . Display($lines[$i]) . "\n"; + is_deeply([$csv->fields()], $fields[$i], + "fields test for $i"); +}