mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Byte Order Marks (BOM) are now stripped when importing CSV files
This commit is contained in:
parent
4cfce30842
commit
77ba8391c4
@ -76,6 +76,7 @@ class CsvBulkLoader extends BulkLoader
|
|||||||
$filepath = Director::getAbsFile($filepath);
|
$filepath = Director::getAbsFile($filepath);
|
||||||
$csvReader = Reader::createFromPath($filepath, 'r');
|
$csvReader = Reader::createFromPath($filepath, 'r');
|
||||||
$csvReader->setDelimiter($this->delimiter);
|
$csvReader->setDelimiter($this->delimiter);
|
||||||
|
$csvReader->stripBom(true);
|
||||||
|
|
||||||
$tabExtractor = function ($row, $rowOffset, $iterator) {
|
$tabExtractor = function ($row, $rowOffset, $iterator) {
|
||||||
foreach ($row as &$item) {
|
foreach ($row as &$item) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\Dev\Tests;
|
namespace SilverStripe\Dev\Tests;
|
||||||
|
|
||||||
|
use League\Csv\Writer;
|
||||||
use SilverStripe\Dev\Tests\CsvBulkLoaderTest\CustomLoader;
|
use SilverStripe\Dev\Tests\CsvBulkLoaderTest\CustomLoader;
|
||||||
use SilverStripe\Dev\Tests\CsvBulkLoaderTest\Player;
|
use SilverStripe\Dev\Tests\CsvBulkLoaderTest\Player;
|
||||||
use SilverStripe\Dev\Tests\CsvBulkLoaderTest\PlayerContract;
|
use SilverStripe\Dev\Tests\CsvBulkLoaderTest\PlayerContract;
|
||||||
@ -300,6 +301,20 @@ class CsvBulkLoaderTest extends SapphireTest
|
|||||||
$this->assertEquals($player->FirstName, "John. He's a good guy. ");
|
$this->assertEquals($player->FirstName, "John. He's a good guy. ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLoadWithByteOrderMark()
|
||||||
|
{
|
||||||
|
$loader = new CsvBulkLoader(Player::class);
|
||||||
|
$loader->load($this->csvPath . 'PlayersWithHeaderAndBOM.csv');
|
||||||
|
|
||||||
|
$players = Player::get();
|
||||||
|
|
||||||
|
$this->assertCount(3, $players);
|
||||||
|
$this->assertListContains([
|
||||||
|
['FirstName' => 'Jamie', 'Birthday' => '1882-01-31'],
|
||||||
|
['FirstName' => 'Järg', 'Birthday' => '1982-06-30'],
|
||||||
|
['FirstName' => 'Jacob', 'Birthday' => '2000-04-30'],
|
||||||
|
], $players);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getLineCount(&$file)
|
protected function getLineCount(&$file)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
FirstName,Biography,Birthday,IsRegistered
|
||||||
|
Jamie,"Pretty old\, with an escaped comma",1882-01-31,1
|
||||||
|
Järg,"Unicode FTW",1982-06-30,1
|
||||||
|
Jacob," Likes leading tabs in his biography",2000-04-30,0
|
|
Loading…
Reference in New Issue
Block a user