1
0
mirror of https://github.com/php/php-src.git synced 2026-03-28 02:02:32 +01:00
Files
archived-php-src/ext/spl/tests/bug69181.phpt
Christoph M. Becker 5d52d472ef Fix #69181: READ_CSV|DROP_NEW_LINE drops newlines within fields
One may argue that `DROP_NEW_LINE` does not make sense in combination
with `READ_CSV`, but without `DROP_NEW_LINE`, `SKIP_EMPTY` does not
skip empty lines at all.  We could fix that, but do not for BC reasons.
Instead we no longer drop newlines in `spl_filesystem_file_read_ex()`
when reading CSV, but handle that in `spl_filesystem_file_read_csv()`
by treating lines with only (CR)LF as being empty as well.

Closes GH-7618.
2022-07-26 18:33:57 +02:00

71 lines
930 B
PHP

--TEST--
Bug #69181 (READ_CSV|DROP_NEW_LINE drops newlines within fields)
--FILE--
<?php
$filename = __DIR__ . "/bug69181.csv";
$csv = <<<CSV
"foo\n\nbar\nbaz",qux
"foo\nbar\nbaz",qux
CSV;
file_put_contents($filename, $csv);
$file = new SplFileObject($filename);
$file->setFlags(SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE | SplFileObject::READ_CSV);
var_dump(iterator_to_array($file));
echo "\n====\n\n";
$file->rewind();
while (($record = $file->fgetcsv())) {
var_dump($record);
}
?>
--EXPECT--
array(2) {
[0]=>
array(2) {
[0]=>
string(12) "foo
bar
baz"
[1]=>
string(3) "qux"
}
[2]=>
array(2) {
[0]=>
string(11) "foo
bar
baz"
[1]=>
string(3) "qux"
}
}
====
array(2) {
[0]=>
string(12) "foo
bar
baz"
[1]=>
string(3) "qux"
}
array(2) {
[0]=>
string(11) "foo
bar
baz"
[1]=>
string(3) "qux"
}
--CLEAN--
<?php
@unlink(__DIR__ . "/bug69181.csv");
?>