From 7d9888e3edac66a713dceae3e0bab34e788c039c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 8 Mar 2011 11:11:54 +0100 Subject: [PATCH] =?utf8?q?Case=20insensitive=20header=20waren=20nicht=20vo?= =?utf8?q?ll=20abgedeckt,=20und=20haben=20Fehler=20bei=20kaputten=20Header?= =?utf8?q?n=20unterdr=C3=BCckt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Helper/Csv.pm | 19 +++++++++++-------- t/helper/csv.t | 21 ++++++++++++++++++++- 2 files changed, 31 insertions(+), 9 deletions(-) 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 -- 2.20.1