Skip to content

Commit 79d86ef

Browse files
LaurentPowerKiKi
Laurent
authored andcommitted
Csv reader avoid notice when the file is empty
Fixes #337
1 parent 4e8e0dc commit 79d86ef

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
1111

1212
- Support numeric condition in SUMIF, SUMIFS, AVERAGEIF, COUNTIF, MAXIF and MINIF - [#683](https://github.com/PHPOffice/PhpSpreadsheet/issues/683)
1313
- SUMIFS containing multiple conditions - [#704](https://github.com/PHPOffice/PhpSpreadsheet/issues/704)
14+
- Csv reader avoid notice when the file is empty - [#743](https://github.com/PHPOffice/PhpSpreadsheet/pull/743)
1415

1516
## [1.5.0] - 2018-10-21
1617

src/PhpSpreadsheet/Reader/Csv.php

+7
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ protected function inferSeparator()
181181
}
182182
}
183183

184+
// If number of lines is 0, nothing to infer : fall back to the default
185+
if ($numberLines === 0) {
186+
$this->delimiter = reset($potentialDelimiters);
187+
188+
return $this->skipBOM();
189+
}
190+
184191
// Calculate the mean square deviations for each delimiter (ignoring delimiters that haven't been found consistently)
185192
$meanSquareDeviations = [];
186193
$middleIdx = floor(($numberLines - 1) / 2);

tests/PhpSpreadsheetTests/Reader/CsvTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ public function providerDelimiterDetection()
6767
'D8',
6868
-58.373161,
6969
],
70+
[
71+
'data/Reader/CSV/empty.csv',
72+
',',
73+
'A1',
74+
null,
75+
],
76+
[
77+
'data/Reader/CSV/no_delimiter.csv',
78+
',',
79+
'A1',
80+
'SingleLine',
81+
],
7082
];
7183
}
7284

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SingleLine

0 commit comments

Comments
 (0)