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: chrispmaiden at gmail dot com
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:
Hi,
I'm not sure how relevant this is but I find that if I remove the SplFileObject::DROP_NEW_LINE
flag from the code at https://3v4l.org/UOIED, I get a pass for
both cases...
The docs about this flag at https://www.php.net/manual/en/class.splfileobject.php
state: "https://www.php.net/manual/en/class.splfileobject.php"
so perhaps that's what's happening with the SplFileObject case?
Best regards,
Chris
Previous Comments:
------------------------------------------------------------------------
[2019-12-04 09:44:48] pandenitz at mail dot ru
And SplFileObject::READ_CSV flag is not required for SplFileObject::fgetcsv()
It's required for SplFileObject::current() and SplFileObject::next(), or I am wrong?
------------------------------------------------------------------------
[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)