Subject: | getline_all() only returns one line on Mac formatted files |
Hello,
I'm not sure if the following is a bug or expected behavior, but when calling getline_all() on a file with \r-only eols, only one row is returned. Subsequent calls to getline() or getline_all() return an empty arrayref.
Here is a one-liner that can be run in the dist directory to demonstrate:
perl -e 'open my $fh, "<", "files/macosx.csv" or die "Oh no."; use Text::CSV_XS; my $csv=Text::CSV_XS->new({binary => 1}); use Data::Dumper; print Dumper($csv->getline_all($fh));'
This happens in perls 5.10, 5.12, 5.14, 5.16, and 5.18. I've tested this back to tag 0.78, and it doesn't seem to have ever worked.
I've attached a failing test case for 45_eol.t. I wasn't sure if I should add it there or in 70_rt.t. I'd be happy to reformat it if you would prefer it in 70_rt.t. Alternatively, if this is not a bug I can submit a doc patch for getline_all() explaining this.
Thank you for your effort in maintaining this module. Have a great weekend!
Cheers,
Fitz
Subject: | 0001-failing-test-case-for-getline_all-on-os-x-linebreaks.patch |
From b1b08a835faf9620b36a0f824183d05181e581d1 Mon Sep 17 00:00:00 2001
From: Fitz Elliott <fitz.elliott@gmail.com>
Date: Fri, 14 Jun 2013 15:23:05 -0400
Subject: [PATCH] failing test case for getline_all() on os x linebreaks
diff --git a/t/45_eol.t b/t/45_eol.t
index bc843c1..525355b 100644
--- a/t/45_eol.t
+++ b/t/45_eol.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 1065;
+use Test::More tests => 1068;
BEGIN {
require_ok "Text::CSV_XS";
@@ -254,4 +254,11 @@ $/ = $def_rs;
close $fh;
}
+{ open my $fh, "<", "files/macosx.csv" or die "Ouch $!";
+ ok (1, "MacOSX exported file - getline_all");
+ ok (my $csv = Text::CSV_XS->new ({ auto_diag => 1, binary => 1 }), "new csv");
+ diag ();
+ is (@{ $csv->getline_all($fh) }, 16, "getline_all gets all lines for osx");
+}
+
1;
--
1.8.3.1