Revision 07a38b9f
Von Sven Schöling vor mehr als 12 Jahren hinzugefügt
SL/Helper/Csv.pm | ||
---|---|---|
111 | 111 |
]) unless $header; |
112 | 112 |
} |
113 | 113 |
|
114 |
# Special case: utf8 BOM. |
|
115 |
# certain software (namely MS Office and notepad.exe insist on prefixing |
|
116 |
# data with a discouraged but valid byte order mark |
|
117 |
# if not removed, the first header field will not be recognized |
|
118 |
if ($header && $header->[0] && $self->encoding =~ /utf-?8/i) { |
|
119 |
$header->[0] =~ s/^\x{FEFF}//; |
|
120 |
} |
|
121 |
|
|
114 | 122 |
return unless $header; |
115 | 123 |
return $self->header([ map { lc } @$header ]); |
116 | 124 |
} |
t/helper/csv.t | ||
---|---|---|
1 |
use Test::More tests => 40;
|
|
1 |
use Test::More tests => 41;
|
|
2 | 2 |
|
3 | 3 |
use lib 't'; |
4 | 4 |
|
... | ... | |
285 | 285 |
##### |
286 | 286 |
|
287 | 287 |
$csv = SL::Helper::Csv->new( |
288 |
file => \"Kaffee",
|
|
289 |
header => [ 'Description' ],
|
|
290 |
class => 'SL::DB::Part',
|
|
288 |
file => \"Kaffee", |
|
289 |
header => [ 'Description' ], |
|
290 |
class => 'SL::DB::Part', |
|
291 | 291 |
); |
292 | 292 |
$csv->parse; |
293 | 293 |
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header as param works'; |
294 | 294 |
|
295 |
##### |
|
296 |
|
|
297 |
$csv = SL::Helper::Csv->new( |
|
298 |
file => \"\x{FEFF}description\nKaffee", |
|
299 |
class => 'SL::DB::Part', |
|
300 |
encoding => 'utf8', |
|
301 |
); |
|
302 |
$csv->parse; |
|
303 |
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'utf8 BOM works (bug 1872)'; |
|
304 |
|
|
295 | 305 |
# vim: ft=perl |
Auch abrufbar als: Unified diff
Bei Importdaten das UTF8 BOM ignorieren.
behebt Bug 1872