Skip Menu |

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

Report information
The Basics
Id: 67813
Status: rejected
Priority: 0/
Queue: Text-CSV

People
Owner: Nobody in particular
Requestors: JKRAMER [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.21
Fixed in: (no value)



When the value in the first column of the first row of a CSV file is quoted, Text::CSV (both _XS and _PP) fails to parse the line, error_diag is "2034EIF - Loose unescaped quote4". See the attached test script and test CSV file for an example. The output when running the script with the test file is: 2034EIF - Loose unescaped quote4 at csvtest.pl line 29, <GEN0> line 1. Enabling the allow_loose_quotes option stops the script from crashing, but the resulting value isn't correct: "foo"|bar|baz instead of foo|bar|baz With the quotes removed from the first value (so the input is: foo;"bar";"baz"), the output is correct: foo|bar|baz Tested with the latest versions of Text::CSV (1.21), Text::CSV_XS (0.81) and Text::CSV_PP (1.29).
Subject: test.csv
"foo";"bar";"baz"
Subject: csvtest.pl
#!/usr/bin/env perl use strict; use warnings; use Text::CSV_XS; use IO::File; die "Usage: $0 <file>\n" if(@ARGV != 1); my ($file) = @ARGV; my $fh = new IO::File($file) or die "Can't open $file. $!.\n"; my $csv = new Text::CSV_XS( { sep_char => ';', quote_char => '"', escape_char => '"', binary => 1, eol => "\n", # allow_loose_quotes => 1, } ); until($fh->eof) { my $row = $csv->getline($fh); die $csv->error_diag unless $row; print join('|', @$row), "\n"; }
After uploading the attached test file I see that there's somegibberish at the beginning, which wasn't visible before. I guess it's some kind of unicode header. Is there a way to work around this? Am Do 28. Apr 2011, 09:09:59, jkramer schrieb: Show quoted text
> When the value in the first column of the first row of a CSV file is > quoted, Text::CSV (both _XS and _PP) fails to parse the line, error_diag > is "2034EIF - Loose unescaped quote4". > > See the attached test script and test CSV file for an example. > > The output when running the script with the test file is: > > 2034EIF - Loose unescaped quote4 at csvtest.pl line 29, <GEN0> line 1. > > Enabling the allow_loose_quotes option stops the script from crashing, > but the resulting value isn't correct: > > "foo"|bar|baz > instead of > foo|bar|baz > > With the quotes removed from the first value (so the input is: > foo;"bar";"baz"), the output is correct: > > foo|bar|baz > > Tested with the latest versions of Text::CSV (1.21), Text::CSV_XS (0.81) > and Text::CSV_PP (1.29).
As a workaround, File::BOM can be used to transparently decode the file correctly: use File::BOM; my $fh = new IO::File($file, '<:via(File::Bom)'); my $row = $csv->getline($fh);