Skip to content

Commit daf79e2

Browse files
Flashwade1990cmb69
authored andcommitted
Fix #75917: SplFileObject::seek broken with CSV flags
Closes GH-7697.
1 parent 7b629af commit daf79e2

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PHP NEWS
55
- Core:
66
. Fixed bug #81656 (GCC-11 silently ignores -R). (Michael Wallner)
77

8+
- Spl:
9+
. Fixed bug #75917 (SplFileObject::seek broken with CSV flags). (Aliaksandr
10+
Bystry)
11+
812
16 Dec 2021, PHP 8.0.14
913

1014
- Core:

ext/spl/spl_directory.c

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

19401940
/* 1) use fgetcsv? 2) overloaded call the function, 3) do it directly */
19411941
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV) || intern->u.file.func_getCurr->common.scope != spl_ce_SplFileObject) {
1942+
spl_filesystem_file_free_line(intern);
1943+
19421944
if (php_stream_eof(intern->u.file.stream)) {
19431945
if (!silent) {
19441946
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot read from file %s", 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)