-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
93 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--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"); | ||
?> |