diff --git a/CHANGELOG.md b/CHANGELOG.md index 474e75d8..c3f6cb5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Support numeric condition in SUMIF, SUMIFS, AVERAGEIF, COUNTIF, MAXIF and MINIF - [#683](https://github.com/PHPOffice/PhpSpreadsheet/issues/683) - SUMIFS containing multiple conditions - [#704](https://github.com/PHPOffice/PhpSpreadsheet/issues/704) +- Csv reader avoid notice when the file is empty - [#743](https://github.com/PHPOffice/PhpSpreadsheet/pull/743) ## [1.5.0] - 2018-10-21 diff --git a/src/PhpSpreadsheet/Reader/Csv.php b/src/PhpSpreadsheet/Reader/Csv.php index 0e18bcc3..25f244c1 100644 --- a/src/PhpSpreadsheet/Reader/Csv.php +++ b/src/PhpSpreadsheet/Reader/Csv.php @@ -181,6 +181,13 @@ class Csv extends BaseReader } } + // If number of lines is 0, nothing to infer : fall back to the default + if ($numberLines === 0) { + $this->delimiter = reset($potentialDelimiters); + + return $this->skipBOM(); + } + // Calculate the mean square deviations for each delimiter (ignoring delimiters that haven't been found consistently) $meanSquareDeviations = []; $middleIdx = floor(($numberLines - 1) / 2); diff --git a/tests/PhpSpreadsheetTests/Reader/CsvTest.php b/tests/PhpSpreadsheetTests/Reader/CsvTest.php index e748cd1b..80186a41 100644 --- a/tests/PhpSpreadsheetTests/Reader/CsvTest.php +++ b/tests/PhpSpreadsheetTests/Reader/CsvTest.php @@ -67,6 +67,18 @@ class CsvTest extends TestCase 'D8', -58.373161, ], + [ + 'data/Reader/CSV/empty.csv', + ',', + 'A1', + null, + ], + [ + 'data/Reader/CSV/no_delimiter.csv', + ',', + 'A1', + 'SingleLine', + ], ]; } diff --git a/tests/data/Reader/CSV/no_delimiter.csv b/tests/data/Reader/CSV/no_delimiter.csv new file mode 100644 index 00000000..ae7c596b --- /dev/null +++ b/tests/data/Reader/CSV/no_delimiter.csv @@ -0,0 +1 @@ +SingleLine \ No newline at end of file