diff --git a/src/Csv.php b/src/Csv.php index d42dcf9c..2375f5d2 100644 --- a/src/Csv.php +++ b/src/Csv.php @@ -1261,7 +1261,7 @@ protected function _check_count($char, $array, $depth, $preferred) { } } - 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 00000000..8c9c3c61 --- /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 7eb2ddf9..22c86550 100644 --- a/tests/methods/ParseTest.php +++ b/tests/methods/ParseTest.php @@ -121,6 +121,15 @@ public function testSingleColumn() { 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;