Skip to content

Commit fd2a6d2

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix #75917: SplFileObject::seek broken with CSV flags
2 parents 8a5c604 + 6f32510 commit fd2a6d2

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

ext/spl/spl_directory.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,8 @@ static int spl_filesystem_file_read_line_ex(zval * this_ptr, spl_filesystem_obje
19361936

19371937
/* 1) use fgetcsv? 2) overloaded call the function, 3) do it directly */
19381938
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV) || intern->u.file.func_getCurr->common.scope != spl_ce_SplFileObject) {
1939+
spl_filesystem_file_free_line(intern);
1940+
19391941
if (php_stream_eof(intern->u.file.stream)) {
19401942
if (!silent) {
19411943
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot read from file %s", ZSTR_VAL(intern->file_name));

ext/spl/tests/bug75917.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #75917 (SplFileObject::seek broken with CSV flags)
3+
--FILE--
4+
<?php
5+
$expected = [
6+
['john', 'doe', '[email protected]', '0123456789'],
7+
['jane', 'doe', '[email protected]'],
8+
];
9+
10+
$tmp = new SplTempFileObject();
11+
foreach ($expected as $row) {
12+
$tmp->fputcsv($row);
13+
}
14+
$tmp->setFlags(0);
15+
$tmp->seek(23);
16+
var_dump($tmp->current());
17+
18+
$tmp->setFlags(SplFileObject::READ_CSV | SplFileObject::SKIP_EMPTY);
19+
$tmp->seek(23);
20+
var_dump($tmp->current());
21+
?>
22+
--EXPECT--
23+
bool(false)
24+
bool(false)

0 commit comments

Comments
 (0)