Skip to content

Commit

Permalink
Merge pull request #358 from on2/master
Browse files Browse the repository at this point in the history
Fatal error with ltrim() when using the EmptyEscapeParser
  • Loading branch information
nyamsprod authored Oct 9, 2019
2 parents 0b843fb + beca510 commit 8effaf0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Polyfill/EmptyEscapeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ private static function extractRecord(): array
self::$line = self::$document->fgets();
do {
$method = 'extractFieldContent';
$buffer = ltrim(self::$line, self::$trim_mask);
$buffer = '';
if (false !== self::$line) {
$buffer = ltrim(self::$line, self::$trim_mask);
}
if (($buffer[0] ?? '') === self::$enclosure) {
$method = 'extractEnclosedFieldContent';
self::$line = $buffer;
Expand Down
19 changes: 19 additions & 0 deletions tests/Polyfill/EmptyEscapeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ public function testPreserveEmptyLines()
}
}

/**
* @covers ::parse
* @covers ::extractRecord
* @covers ::extractFieldContent
* @covers ::extractEnclosedFieldContent
*/
public function testReadingOnlyStream()
{
$expected = [
['john', 'doe', '[email protected]'],
[null],
];

$stream = Stream::createFromPath(__DIR__.'/../data/foo_readonly.csv');
foreach (EmptyEscapeParser::parse($stream) as $offset => $record) {
self::assertSame($expected[$offset], $record);
}
}

/**
* @covers ::parse
* @covers ::extractRecord
Expand Down

0 comments on commit 8effaf0

Please sign in to comment.