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

Report information
The Basics
Id:
81295
Status:
resolved
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
adam.botbyl [...] revsolns.com
Cc:
AdminCc:

BugTracker
Severity:
Normal
Broken in:
0.93
Fixed in:
0.95



Text::CSV_XS does not properly handled a escaped sep_char if it is the only item in a data field. i.e. if sep_char => ',' and escape_char => '\\' and data is 'testing,\,,fields' data will show up as 4 columns instead of 3. However, this is remedied if the escape_char is double used inside a column with only the sep_char in it i.e. if sep_char => ',' and escape_char => '\\' and data is 'testing,\\,,fields' data will show up properly as 3 columns. Example script below: #!/usr/bin/perl; use Text::CSV_XS; use Data::Dumper; my $csv = Text::CSV_XS->new({quote_char => undef, escape_char => '\\', sep_char => ','}); print "Properly escaped sep_char which should show up as 4 columns showing up as 5 columns:\n"; $csv->parse('hello,wo\\,rld,\\,,testing'); print Dumper($csv->fields())."\n"; $csv->parse('hello,wo\\,rld,\\\\,,testing'); print "Double escaped sep_char showing up correctly as 4 columns:\n"; print Dumper($csv->fields()); __END__ From testing it makes no difference what escape and sep chars are, the problem still exists.
Subject: Re: [rt.cpan.org #81295]
Date: Tue, 20 Nov 2012 13:44:21 +0100
To: bug-Text-CSV_XS@rt.cpan.org
From: "H.Merijn Brand" <h.m.brand@xs4all.nl>
On Tue, 20 Nov 2012 04:07:07 -0500, "Adam via RT" <bug-Text-CSV_XS@rt.cpan.org> wrote:
Show quoted text
> Text::CSV_XS does not properly handled a escaped sep_char if it is the > only item in a data field.
in an unquoted data field to be precise
Show quoted text
> i.e. if sep_char => ',' and escape_char => '\\' and data is > 'testing,\,,fields' data will show up as 4 columns instead of 3.
And when I "fix" that, I will break backward compatibility :( As from when I took over, Text::CSV_XS did not allow the escape character to be the first character of an unquoted field.
Show quoted text
> However, this is remedied if the escape_char is double used inside a > column with only the sep_char in it > > i.e. if sep_char => ',' and escape_char => '\\' and data is > 'testing,\\,,fields' data will show up properly as 3 columns.
I can give an explanation based on the current code, but that doesn't fix the problem :( I really have to think about this for a while and re-read the existing CSV docs to see if and how it should/could be supported For now the only way to use this is to have those fields quoted
Show quoted text
> Example script below: > > #!/usr/bin/perl; > use Text::CSV_XS; > use Data::Dumper; > my $csv = Text::CSV_XS->new({quote_char => undef, escape_char => '\\', > sep_char => ','}); > print "Properly escaped sep_char which should show up as 4 columns > showing up as 5 columns:\n"; > $csv->parse('hello,wo\\,rld,\\,,testing'); > print Dumper($csv->fields())."\n"; > > $csv->parse('hello,wo\\,rld,\\\\,,testing'); > print "Double escaped sep_char showing up correctly as 4 columns:\n"; > print Dumper($csv->fields()); > > __END__ > > From testing it makes no difference what escape and sep chars are, the > problem still exists.
-- H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/ using perl5.00307 .. 5.17 porting perl5 on HP-UX, AIX, and openSUSE http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/ http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/
I added a new attribute to make this possible without breaking backward compatibility: allow_unquoted_escape There is a backward compatability issue in that the escape character, when differing from the quotation character, cannot be on the first position of a field. e.g. with C<quote_char> equal to the default C<"> and C<escape_char> set to C<\>, this would be illegal: 1,\0,2 To overcome issues with backward compatibility, you can allow this by setting this attribute to 1.


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.