diff --git a/lib/WebGUI/SQL.pm b/lib/WebGUI/SQL.pm index bf271d9b6..b5379aad4 100644 --- a/lib/WebGUI/SQL.pm +++ b/lib/WebGUI/SQL.pm @@ -679,7 +679,7 @@ sub quickCSV { my $params = shift; my ($sth, $output, @data); - my $csv = Text::CSV_XS->new({ eol => "\n" }); + my $csv = Text::CSV_XS->new({ eol => "\n", binary => 1 }); $sth = $self->prepare($sql); $sth->execute($params); @@ -688,7 +688,10 @@ sub quickCSV { $output = $csv->string(); while (@data = $sth->array) { - return undef unless $csv->combine(@data); + if ( ! $csv->combine(@data) ) { + $self->session->log->error( "Problem creating CSV row: " . $csv->error_diag ); + return undef; + } $output .= $csv->string(); } diff --git a/t/SQL.t b/t/SQL.t index 483ea065e..5b3469ef8 100644 --- a/t/SQL.t +++ b/t/SQL.t @@ -17,7 +17,7 @@ use WebGUI::Session; use Data::Dumper; use Test::Deep; -use Test::More tests => 56; # increment this value for each test you create +use Test::More tests => 57; # increment this value for each test you create my $session = WebGUI::Test->session; @@ -299,3 +299,13 @@ cmp_deeply( 'Check table structure', ); +#---------------------------------------------------------------------------- +# REGRESSIONS + +# 11940 : quickCSV chokes on newlines +$session->db->write( + 'INSERT INTO testTable (myIndex,message,myKey) VALUES (?,?,?)', + [ 10, "a\ntest", 'B' ], +); +ok( $session->db->quickCSV( 'SELECT * FROM testTable' ), 'get some output even with newlines in data' ); +