mirror of
https://github.com/php/php-src.git
synced 2024-09-21 09:57:23 +00:00
Fix #81477: LimitIterator + SplFileObject regression in 8.0.1
We must not free the read line, if the `READ_AHEAD` flag is set. This also restores the expectations of SplFileObject_next_variation002.phpt. Closes GH-7518.
This commit is contained in:
parent
e2d9ca7b19
commit
ee5711de33
1
NEWS
1
NEWS
@ -32,6 +32,7 @@ PHP NEWS
|
||||
- SPL:
|
||||
. Fixed bug #80663 (Recursive SplFixedArray::setSize() may cause double-free).
|
||||
(cmb, Nikita, Tyson Andre)
|
||||
. Fixed bug #81477 (LimitIterator + SplFileObject regression in 8.0.1). (cmb)
|
||||
|
||||
- Standard:
|
||||
. Fixed bug #69751 (Change Error message of sprintf/printf for missing/typo
|
||||
|
@ -2738,7 +2738,9 @@ PHP_METHOD(SplFileObject, seek)
|
||||
}
|
||||
if (line_pos > 0) {
|
||||
intern->u.file.current_line_num++;
|
||||
spl_filesystem_file_free_line(intern);
|
||||
if (!SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_AHEAD)) {
|
||||
spl_filesystem_file_free_line(intern);
|
||||
}
|
||||
}
|
||||
} /* }}} */
|
||||
|
||||
|
@ -26,5 +26,5 @@ echo $s->current();
|
||||
--EXPECT--
|
||||
//line 3
|
||||
//line 4
|
||||
//line 3
|
||||
//line 4
|
||||
//line 5
|
||||
|
28
ext/spl/tests/bug81477.phpt
Normal file
28
ext/spl/tests/bug81477.phpt
Normal file
@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
Bug #81477 (LimitIterator + SplFileObject regression in 8.0.1)
|
||||
--FILE--
|
||||
<?php
|
||||
$filename = __DIR__ . '/bug81477.csv';
|
||||
|
||||
$s = fopen($filename, 'w+');
|
||||
fwrite($s, "foo,bar\nbaz,bat\nmore,data\n");
|
||||
fclose($s);
|
||||
|
||||
$sfo = new SplFileObject($filename);
|
||||
$sfo->setFlags(SplFileObject::READ_AHEAD);
|
||||
$limitIter = new LimitIterator($sfo, 1, -1);
|
||||
|
||||
foreach($limitIter as $row) {
|
||||
var_dump($row);
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
string(8) "baz,bat
|
||||
"
|
||||
string(10) "more,data
|
||||
"
|
||||
string(0) ""
|
||||
--CLEAN--
|
||||
<?php
|
||||
@unlink(__DIR__ . '/bug81477.csv');
|
||||
?>
|
Loading…
Reference in New Issue
Block a user