kenahoo / Perl-Parse-CSV

Highly flexible CSV parser for large files
0 stars 4 forks source link

casing in header changes when upgrading from 2.05 to 2.06 #12

Open kjellkvinge opened 2 years ago

kjellkvinge commented 2 years ago

Hi. Thank you for your work on this package.

Not sure if it is a bug or feature, but upgrading from 2.05 to 2.06 changes the keys in the hash returned when using "names".

Consider the following test

{
    my $data = <<EOF;
this,file,contains,CaseSensitiveHEADER
a,b,c,d
one,two,three,four
EOF

    open my $fh, '<', \$data or die $!;
    my $csv = Parse::CSV->new(handle => $fh, names => 1);

    my $row = $csv->fetch();

    is_deeply($row,
        {
            this                  => "a",
            file                  => "b",
            contains              => "c",
            'CaseSensitiveHEADER' => 'd',
        },
        '->fetch returns as expected');

}

This works in version 2.05. We get the following row:

{
    CaseSensitiveHEADER   "d",
    contains              "c",
    file                  "b",
    this                  "a"
}

but in 2.06, the returned hash looks like this:

{
    casesensitiveheader   "d",
    contains              "c",
    file                  "b",
    this                  "a"
}

This is probably caused by the behaviour of csv_xs->header() which was introduced in dfcc2ac1b750aa72169723910d7689a7af6503b2

Thank you. br.

kjellkvinge commented 2 years ago

on a side note, I also got some errors regarding non-standard ascii characters in header, i.e

CSV_XS ERROR: 2037 - EIF - Binary character in unquoted field, binary off @ rec 0 pos 18 field 2

These errors is also caused by introduction of the csv_xz->header()

but, I think I found a way around this.