Support CSV files with data wrapping a lot of lines
If there is "line" splited on lot of lines we can reach limit of recursion nesting. It's better to use while instead of recursion. Closes #1468
This commit is contained in:
parent
c4931de1f9
commit
3090c1e73f
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
|||
### Added
|
||||
|
||||
- Support writing to streams in all writers [#1292](https://github.com/PHPOffice/PhpSpreadsheet/issues/1292)
|
||||
- Support CSV files with data wrapping a lot of lines [#1468](https://github.com/PHPOffice/PhpSpreadsheet/pull/1468)
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -236,12 +236,14 @@ class Csv extends BaseReader
|
|||
/**
|
||||
* Get the next full line from the file.
|
||||
*
|
||||
* @param string $line
|
||||
*
|
||||
* @return bool|string
|
||||
* @return false|string
|
||||
*/
|
||||
private function getNextLine($line = '')
|
||||
private function getNextLine()
|
||||
{
|
||||
$line = '';
|
||||
$enclosure = '(?<!' . preg_quote($this->escapeCharacter, '/') . ')' . preg_quote($this->enclosure, '/');
|
||||
|
||||
do {
|
||||
// Get the next line in the file
|
||||
$newLine = fgets($this->fileHandle);
|
||||
|
||||
|
@ -254,15 +256,11 @@ class Csv extends BaseReader
|
|||
$line = $line . $newLine;
|
||||
|
||||
// Drop everything that is enclosed to avoid counting false positives in enclosures
|
||||
$enclosure = '(?<!' . preg_quote($this->escapeCharacter, '/') . ')'
|
||||
. preg_quote($this->enclosure, '/');
|
||||
$line = preg_replace('/(' . $enclosure . '.*' . $enclosure . ')/Us', '', $line);
|
||||
|
||||
// See if we have any enclosures left in the line
|
||||
// if we still have an enclosure then we need to read the next line as well
|
||||
if (preg_match('/(' . $enclosure . ')/', $line) > 0) {
|
||||
$line = $this->getNextLine($line);
|
||||
}
|
||||
} while (preg_match('/(' . $enclosure . ')/', $line) > 0);
|
||||
|
||||
return $line;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue