Skip to content

Commit

Permalink
Fix #75917: SplFileObject::seek broken with CSV flags
Browse files Browse the repository at this point in the history
Closes GH-7697.
  • Loading branch information
Flashwade1990 authored and cmb69 committed Dec 6, 2021
1 parent 7b629af commit daf79e2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ PHP NEWS
- Core:
. Fixed bug #81656 (GCC-11 silently ignores -R). (Michael Wallner)

- Spl:
. Fixed bug #75917 (SplFileObject::seek broken with CSV flags). (Aliaksandr
Bystry)

16 Dec 2021, PHP 8.0.14

- Core:
Expand Down
2 changes: 2 additions & 0 deletions ext/spl/spl_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,8 @@ static int spl_filesystem_file_read_line_ex(zval * this_ptr, spl_filesystem_obje

/* 1) use fgetcsv? 2) overloaded call the function, 3) do it directly */
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV) || intern->u.file.func_getCurr->common.scope != spl_ce_SplFileObject) {
spl_filesystem_file_free_line(intern);

if (php_stream_eof(intern->u.file.stream)) {
if (!silent) {
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot read from file %s", intern->file_name);
Expand Down
24 changes: 24 additions & 0 deletions ext/spl/tests/bug75917.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Bug #75917 (SplFileObject::seek broken with CSV flags)
--FILE--
<?php
$expected = [
['john', 'doe', 'john.doe@example.com', '0123456789'],
['jane', 'doe', 'jane.doe@example.com'],
];

$tmp = new SplTempFileObject();
foreach ($expected as $row) {
$tmp->fputcsv($row);
}
$tmp->setFlags(0);
$tmp->seek(23);
var_dump($tmp->current());

$tmp->setFlags(SplFileObject::READ_CSV | SplFileObject::SKIP_EMPTY);
$tmp->seek(23);
var_dump($tmp->current());
?>
--EXPECT--
bool(false)
bool(false)

0 comments on commit daf79e2

Please sign in to comment.