From: Sven Schöling Date: Tue, 8 Mar 2011 10:11:54 +0000 (+0100) Subject: Case insensitive header waren nicht voll abgedeckt, und haben Fehler bei kaputten... X-Git-Tag: release-2.7.0beta1~396^2~63 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=7d9888e3edac66a713dceae3e0bab34e788c039c;p=kivitendo-erp.git Case insensitive header waren nicht voll abgedeckt, und haben Fehler bei kaputten Headern unterdrückt. --- diff --git a/SL/Helper/Csv.pm b/SL/Helper/Csv.pm index a30122e04..3132b2846 100644 --- a/SL/Helper/Csv.pm +++ b/SL/Helper/Csv.pm @@ -99,17 +99,20 @@ sub _open_file { sub _check_header { my ($self, %params) = @_; - return $self->header if $self->header; + my $header = $self->header; - my $header = $self->_csv->getline($self->_io); + if (! $header) { + $header = $self->_csv->getline($self->_io); - $self->_push_error([ - $self->_csv->error_input, - $self->_csv->error_diag, - 0, - ]) unless $header; + $self->_push_error([ + $self->_csv->error_input, + $self->_csv->error_diag, + 0, + ]) unless $header; + } - $self->header([ map { lc } @{ $header } ]); + return unless $header; + return $self->header([ map { lc } @$header ]); } sub _parse_data { diff --git a/t/helper/csv.t b/t/helper/csv.t index d4a157199..e4a625430 100644 --- a/t/helper/csv.t +++ b/t/helper/csv.t @@ -1,4 +1,4 @@ -use Test::More tests => 37; +use Test::More tests => 39; use SL::Dispatcher; use Data::Dumper; use utf8; @@ -274,4 +274,23 @@ $csv = SL::Helper::Csv->new( $csv->parse; is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'eol bug at the end of files'; +##### + +$csv = SL::Helper::Csv->new( + file => \"Description\nKaffee", + class => 'SL::DB::Part', +); +$csv->parse; +is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header from csv works'; + +##### + +$csv = SL::Helper::Csv->new( + file => \"Kaffee", + header => [ 'Description' ], + class => 'SL::DB::Part', +); +$csv->parse; +is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header as param works'; + # vim: ft=perl