diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 568ae82..a2c7def 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -495,6 +495,8 @@ class parseCSV { if (is_null($enclosure)) { $enclosure = $this->enclosure; + } else { + $this->enclosure = $enclosure; } if (is_null($preferred)) { diff --git a/tests/methods/auto_test.php b/tests/methods/auto_test.php new file mode 100644 index 0000000..124a9ef --- /dev/null +++ b/tests/methods/auto_test.php @@ -0,0 +1,26 @@ +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); + } +} diff --git a/tests/methods/fixtures/auto-double-enclosure.csv b/tests/methods/fixtures/auto-double-enclosure.csv new file mode 100644 index 0000000..47f7bec --- /dev/null +++ b/tests/methods/fixtures/auto-double-enclosure.csv @@ -0,0 +1,3 @@ +"column1","column2" +"value1","value2" +"value3","value4" \ No newline at end of file diff --git a/tests/methods/fixtures/auto-single-enclosure.csv b/tests/methods/fixtures/auto-single-enclosure.csv new file mode 100644 index 0000000..716beb2 --- /dev/null +++ b/tests/methods/fixtures/auto-single-enclosure.csv @@ -0,0 +1,3 @@ +'column1','column2' +'value1','value2' +'value3','value4' \ No newline at end of file