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

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

People
Owner:
Nobody in particular
Requestors:
toapole [...] gmail.com
Cc:
AdminCc:

BugTracker
Severity:
(no value)
Broken in:
0.29
Fixed in:
1.42



Subject: types behavior discrepancy
Hello Got strange behavior of types feature while converting csv to json data. Here is example script which demonstrates the issue: use strict; use Text::CSV_XS (); use JSON; my $data = <<\csv; f1,f2 1.1,2 4.2,5 4.4,6 3.2,5 csv open my $fh, '<', \$data or die $!; my $csv = Text::CSV_XS->new; my $csv_t = Text::CSV_XS->new; my @result; push @result, $csv->getline($fh); # ok: expecting strings $csv->types([Text::CSV_XS::NV, Text::CSV_XS::IV]); push @result, $csv->getline($fh); # err: expecting numbers, but got strings $csv_t->types([Text::CSV_XS::NV, Text::CSV_XS::IV]); push @result, $csv_t->getline($fh); # ok: expecting numbers $csv_t->types(undef); push @result, $csv_t->getline($fh); # ok: expecting strings $csv_t->types([Text::CSV_XS::NV, Text::CSV_XS::IV]); push @result, $csv_t->getline($fh); # err: expecting numbers in JSON print JSON->new->pretty->encode(\@result);
Subject: csv-type.pl
use strict; use Text::CSV_XS (); use JSON; my $data = <<\csv; f1,f2 1.1,2 4.2,5 4.4,6 3.2,5 csv open my $fh, '<', \$data or die $!; my $csv = Text::CSV_XS->new; my $csv_t = Text::CSV_XS->new; my @result; push @result, $csv->getline($fh); # ok: expecting strings $csv->types([Text::CSV_XS::NV, Text::CSV_XS::IV]); push @result, $csv->getline($fh); # err: expecting numbers, but got strings $csv_t->types([Text::CSV_XS::NV, Text::CSV_XS::IV]); push @result, $csv_t->getline($fh); # ok: expecting numbers $csv_t->types(undef); push @result, $csv_t->getline($fh); # ok: expecting strings $csv_t->types([Text::CSV_XS::NV, Text::CSV_XS::IV]); push @result, $csv_t->getline($fh); # err: expecting numbers in JSON print JSON->new->pretty->encode(\@result);
On 2020-04-14 08:56:38, egor wrote:
Show quoted text
> Hello > > Got strange behavior of types feature while converting csv to json data. > > Here is example script which demonstrates the issue:
Could you please be more specific with what you believe the problem to be? For example, what do you get, and what do you expect it should be instead?
On Tue Apr 14 12:43:19 2020, ETHER wrote:
Show quoted text
> On 2020-04-14 08:56:38, egor wrote:
> > Hello > > > > Got strange behavior of types feature while converting csv to json data. > > > > Here is example script which demonstrates the issue:
> > Could you please be more specific with what you believe the problem to be? > For example, what do you get, and what do you expect it should be instead?
I'm expecting consistent behavior in regard of internal flags of returning scalars when using "types" feature. Because it's affects encoding behavior of serializers like JSON, YAML::XS Perhaps the following script will be more clear.
Subject: csv-type-peek.pl
use strict; use Devel::Peek; use Text::CSV_XS; my $csv = Text::CSV_XS->new; my $data = '3.14,1'; my @types = (Text::CSV_XS::NV, Text::CSV_XS::IV); my ($nv, $iv); print STDERR "with types(expected flags):\n"; $csv->types(\@types); $csv->parse($data); ($nv, $iv) = $csv->fields; Dump $nv; # PVNV with NOK flag Dump $iv; # PVIV with IOK flag print STDERR "\nwithout types(expected flags):\n"; $csv->types(undef); $csv->parse($data); ($nv, $iv) = $csv->fields; Dump $nv; # PVNV with POK flag Dump $iv; # PVIV with POK flag print STDERR "\nwith types(unexpected flags):\n"; $csv->types(\@types); $csv->parse($data); ($nv, $iv) = $csv->fields; Dump $nv; # PVNV with POK flag, but NOK expected Dump $iv; # PVIV with POK flat, but IOK expected
Fixed in https://github.com/Tux/Text-CSV_XS/commit/6d48f607772a1aefd4b93ff79d7ae3e02ddf660d - but I am still thinking about tests (which should not add dependencies and work back to 5.6.0). I know how to check using Data::Peek, but that is not an option
On Thu Apr 30 09:29:09 2020, HMBRAND wrote:
Show quoted text
> Fixed in https://github.com/Tux/Text- > CSV_XS/commit/6d48f607772a1aefd4b93ff79d7ae3e02ddf660d - but I am > still thinking about tests (which should not add dependencies and work > back to 5.6.0). I know how to check using Data::Peek, but that is not > an option
Thank you!


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.