]) unless $header;
}
+ # Special case: utf8 BOM.
+ # certain software (namely MS Office and notepad.exe insist on prefixing
+ # data with a discouraged but valid byte order mark
+ # if not removed, the first header field will not be recognized
+ if ($header && $header->[0] && $self->encoding =~ /utf-?8/i) {
+ $header->[0] =~ s/^\x{FEFF}//;
+ }
+
return unless $header;
return $self->header([ map { lc } @$header ]);
}
-use Test::More tests => 40;
+use Test::More tests => 41;
use lib 't';
#####
$csv = SL::Helper::Csv->new(
- file => \"Kaffee",
- header => [ 'Description' ],
- class => 'SL::DB::Part',
+file => \"Kaffee",
+header => [ 'Description' ],
+class => 'SL::DB::Part',
);
$csv->parse;
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header as param works';
+#####
+
+$csv = SL::Helper::Csv->new(
+ file => \"\x{FEFF}description\nKaffee",
+ class => 'SL::DB::Part',
+ encoding => 'utf8',
+);
+$csv->parse;
+is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'utf8 BOM works (bug 1872)';
+
# vim: ft=perl