Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error with ltrim() when using the EmptyEscapeParser #358

Merged
merged 4 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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