Csv reader avoid notice when the file is empty

Fixes #337
This commit is contained in:
Laurent 2018-10-26 19:14:45 +02:00 committed by Adrien Crivelli
parent 4e8e0dc01b
commit 79d86ef5cc
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
4 changed files with 21 additions and 0 deletions

View File

@ -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) - 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) - 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 ## [1.5.0] - 2018-10-21

View File

@ -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) // Calculate the mean square deviations for each delimiter (ignoring delimiters that haven't been found consistently)
$meanSquareDeviations = []; $meanSquareDeviations = [];
$middleIdx = floor(($numberLines - 1) / 2); $middleIdx = floor(($numberLines - 1) / 2);

View File

@ -67,6 +67,18 @@ class CsvTest extends TestCase
'D8', 'D8',
-58.373161, -58.373161,
], ],
[
'data/Reader/CSV/empty.csv',
',',
'A1',
null,
],
[
'data/Reader/CSV/no_delimiter.csv',
',',
'A1',
'SingleLine',
],
]; ];
} }

View File

@ -0,0 +1 @@
SingleLine
1 SingleLine