Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling $csv->header breaks auto_diag in 1.40 #19

Closed
afresh1 opened this issue Jan 29, 2020 · 8 comments
Closed

Calling $csv->header breaks auto_diag in 1.40 #19

afresh1 opened this issue Jan 29, 2020 · 8 comments

Comments

@afresh1
Copy link

afresh1 commented Jan 29, 2020

In this short test script, I expect a "CSV_XS ERROR: 2023 - EIQ - QUO character not allowed @ rec 2 pos 6 field 2" exception in the loop, and that happens if the line calling $csv->header is commented out. However, after calling ->header it seems Text::CSV_XS::error_diag is getting called with no arguments and so $self is falsy and so the croak is never triggered. Instead we fall through to the "why no auto_diag" exception.

#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV_XS;

my $csv = Text::CSV_XS->new( { auto_diag => 2 } );
$csv->header(*DATA); # comment out this line to hide the bug
while ( my $row = $csv->getline(*DATA) ) { print "$row->[0]\n" }
die "why no auto_diag for: " . $csv->error_diag
    if $csv->error_diag and $csv->error_diag != 2012;

__DATA__
Foo,Bar,Baz
a,xxx,1
b,"xx"xx", 2
c, foo , 3
@Tux
Copy link
Owner

Tux commented Jan 30, 2020

It might help to tell which version of perl on what OS and which version of Text::CSV_XS you are using. I now see what you mean.

#!/pro/bin/perl

use 5.16.2;
use warnings;

use Text::CSV_XS;

binmode STDOUT, ":encoding(utf-8)";
binmode STDERR, ":encoding(utf-8)";

my $h = shift // 0;

sub show {
    say join ", " => map { "\x{231e}$_\x{231d}" } @_;
    } # show

my $csv = Text::CSV_XS->new ({ auto_diag => 2 });
if ($h) {
    say "Calling header";
    show ($csv->header (*DATA)); # comment out this line to hide the bug
    }
while (my $row = $csv->getline (*DATA)) {
    show (@$row);
    }
say "EOF: ", $csv->eof ? "Yes" : "No";
$csv->error_diag;

__DATA__
Foo,Bar,Baz
a,xxx,1
b,"xx"xx", 2
c, foo , 3
$ perl issue#19.pl 0
⌞Foo⌝, ⌞Bar⌝, ⌞Baz⌝
⌞a⌝, ⌞xxx⌝, ⌞1⌝
# CSV_XS ERROR: 2023 - EIQ - QUO character not allowed @ rec 2 pos 6 field 2
Exit 2
$ perl issue#19.pl 1
Calling header
⌞foo⌝, ⌞bar⌝, ⌞baz⌝
⌞a⌝, ⌞xxx⌝, ⌞1⌝
EOF: No
# CSV_XS ERROR: 2023 - EIQ - QUO character not allowed @ rec 3 pos 6 field 2
Exit 2

Tux pushed a commit that referenced this issue Jan 30, 2020
@afresh1
Copy link
Author

afresh1 commented Jan 30, 2020

I apologize, I should have included OS and perl version information, although it doesn't seem to make a difference. I did say 1.40 in the description, but wasn't clear that was Text::CSV_XS 1.40. I ran the script with the latest release of each even version of perl from 5.10 through 5.30 and on perl 5.31 all with the same results. This was both on linux and OpenBSD.

@Tux
Copy link
Owner

Tux commented Jan 30, 2020

I can reproduce, and I will look into it. $work interferes though.
And again, thanks for reporting!

@Tux
Copy link
Owner

Tux commented Jan 31, 2020

@afresh1 can you pull and try? I think I fixed it. (tests now also included)

@afresh1
Copy link
Author

afresh1 commented Jan 31, 2020

That does seem to work the way I expect, thank you!

@afresh1 afresh1 closed this as completed Jan 31, 2020
@Tux
Copy link
Owner

Tux commented Feb 25, 2020

@afresh1 any feedback?

@afresh1
Copy link
Author

afresh1 commented Feb 26, 2020

Feedback beyond the fix seems to be good? I am not sure what feedback you are asking for.

@Tux
Copy link
Owner

Tux commented Feb 26, 2020

/me missed that you closed it. sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants