diff --git a/src/Csv.php b/src/Csv.php index a9a4841..98b21e9 100644 --- a/src/Csv.php +++ b/src/Csv.php @@ -1261,7 +1261,7 @@ class Csv { } } - if ($equal) { + if ($equal || $depth === 1) { $match = $almost ? 2 : 1; $pref = strpos($preferred, $char); $pref = ($pref !== false) ? str_pad($pref, 3, '0', STR_PAD_LEFT) : '999'; diff --git a/tests/example_files/single_row.csv b/tests/example_files/single_row.csv new file mode 100644 index 0000000..8c9c3c6 --- /dev/null +++ b/tests/example_files/single_row.csv @@ -0,0 +1 @@ +C1,C2,C3 diff --git a/tests/methods/ParseTest.php b/tests/methods/ParseTest.php index 7eb2ddf..22c8655 100644 --- a/tests/methods/ParseTest.php +++ b/tests/methods/ParseTest.php @@ -121,6 +121,15 @@ class ParseTest extends TestCase { self::assertEquals($expected, $this->csv->data); } + public function testSingleRow() { + $this->csv->auto(__DIR__ . '/../example_files/single_row.csv'); + self::assertEquals([], $this->csv->data, 'Single row is detected as header'); + $this->csv->heading = false; + $this->csv->auto(__DIR__ . '/../example_files/single_row.csv'); + $expected = [['C1', 'C2', 'C3']]; + self::assertEquals($expected, $this->csv->data); + } + public function testMatomoData() { // Matomo (Piwik) export cannot be read with $this->csv->use_mb_convert_encoding = true;