Bug #78907 [Com]: SplFileObject::fgetcsv() truncates data after CR char
Edit report at https://bugs.php.net/bug.php?id=78907&edit=1
ID: 78907
Comment by: pandenitz at mail dot ru
Reported by: pandenitz at mail dot ru
Summary: SplFileObject::fgetcsv() truncates data after CR
char
Status: Verified
Type: Bug
Package: SPL related
Operating System: Ubuntu 16.0.4
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
And SplFileObject::READ_CSV flag is not required for SplFileObject::fgetcsv()
It's required for SplFileObject::current() and SplFileObject::next(), or I am wrong?
Previous Comments:
------------------------------------------------------------------------
[2019-12-04 08:45:56] pandenitz at mail dot ru
See modified https://3v4l.org/UOIED with enclosures added,
auto_detect_line_endings = 0 and "\0" escape (ntw why not "\\" ?).
The code has two variants for both SplFileObject::fgetcsv() and usual fgetcsv()
SplFileObject::fgetcsv() is still incorrect.
CSV can or can not have enclosures. It fails even with CR inside the enclosed column.
------------------------------------------------------------------------
[2019-12-04 08:16:20] cmb@php.net
Firstly, this CSV is invalid, since any linebreaks inside a field
need to be enclosed in $enclosure characters. Also, you need to
set the READ_CSV flag. But even if that is done[1], the line is
still skipped. It works as expected with fgetcsv()[2], though.
[1] <https://3v4l.org/ga46S>
[2] <https://3v4l.org/Hg5TT>
------------------------------------------------------------------------
[2019-12-04 07:26:37] pandenitz at mail dot ru
Description:
------------
Tested on PHP 7.1.26 - 7.4.0
See https://3v4l.org/k1B5Y
The initial CSV file has CRLF line breaks.
4th row (starting from 0) has CR inside.
The parser truncates the chars after this CR and the line is incompletely parsed into an array.
Test script:
---------------
https://3v4l.org/k1B5Y
Expected result:
----------------
The row should be parsed correctly with an array element that contains CR inside because CRLF is the
real linebreak.
Actual result:
--------------
The row is truncated after CR.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78907&edit=1
Thread (6 messages)