Merge branch 'PHP-8.1'

* PHP-8.1:
  Fix #75917: SplFileObject::seek broken with CSV flags
This commit is contained in:
Christoph M. Becker 2021-12-06 19:03:13 +01:00
commit fd2a6d2360
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6
2 changed files with 26 additions and 0 deletions

View file

@ -1936,6 +1936,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", ZSTR_VAL(intern->file_name));

View file

@ -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)