mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
Incorrect parsing with single quote during auto-detection delimiter.
This commit is contained in:
committed by
Christian Bläul
parent
631fae5191
commit
5a9a10aeed
@@ -495,6 +495,8 @@ class parseCSV {
|
||||
|
||||
if (is_null($enclosure)) {
|
||||
$enclosure = $this->enclosure;
|
||||
} else {
|
||||
$this->enclosure = $enclosure;
|
||||
}
|
||||
|
||||
if (is_null($preferred)) {
|
||||
|
||||
26
tests/methods/auto_test.php
Normal file
26
tests/methods/auto_test.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
class auto_Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function autoQuotesDataProvider()
|
||||
{
|
||||
return array(
|
||||
array('tests/methods/fixtures/auto-double-enclosure.csv', '"'),
|
||||
array('tests/methods/fixtures/auto-single-enclosure.csv', "'"),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider autoQuotesDataProvider
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $enclosure
|
||||
*/
|
||||
public function testAutoQuotes($file, $enclosure)
|
||||
{
|
||||
$csv = new parseCSV();
|
||||
$csv->auto($file, true, null, null, $enclosure);
|
||||
$this->assertArrayHasKey('column1', $csv->data[0], 'Data parsed incorrectly with enclosure ' . $enclosure);
|
||||
$this->assertEquals('value1', $csv->data[0]['column1'], 'Data parsed incorrectly with enclosure ' . $enclosure);
|
||||
}
|
||||
}
|
||||
3
tests/methods/fixtures/auto-double-enclosure.csv
Normal file
3
tests/methods/fixtures/auto-double-enclosure.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
"column1","column2"
|
||||
"value1","value2"
|
||||
"value3","value4"
|
||||
|
3
tests/methods/fixtures/auto-single-enclosure.csv
Normal file
3
tests/methods/fixtures/auto-single-enclosure.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
'column1','column2'
|
||||
'value1','value2'
|
||||
'value3','value4'
|
||||
|
Reference in New Issue
Block a user