Bug #66588 [PATCH]: SplFileObject::fgetcsv incorrectly returns a row on premature EOF

From: Date: Thu, 30 Sep 2021 09:33:42 +0000
Subject: Bug #66588 [PATCH]: SplFileObject::fgetcsv incorrectly returns a row on premature EOF
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236931@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66588&edit=1 ID: 66588 Patch added by: cmb@php.net Reported by: jameshfisher at gmail dot com Summary: SplFileObject::fgetcsv incorrectly returns a row on premature EOF Status: Verified Type: Bug Package: SPL related Operating System: Ubuntu 12.04.4 LTS PHP Version: 5.5.8 Block user comment: N Private report: N New Comment: The following pull request has been associated: Patch Name: Fix #66588: SplFileObject::fgetcsv incorrectly returns a row on premature EOF. On GitHub: https://github.com/php/php-src/pull/7535 Patch: https://github.com/php/php-src/pull/7535.patch Previous Comments: ------------------------------------------------------------------------ [2021-07-06 11:57:19] cmb@php.net To clarify: this is about the different behavior with and without trailing newline (<https://3v4l.org/VHrCH>); both should behave the same, and applying Postel's law, neither should return FALSE. ------------------------------------------------------------------------ [2021-07-06 11:01:24] cmb@php.net > This behavior is a deliberate design decision[1], […] No, the behavior actually makes no sense. ------------------------------------------------------------------------ [2020-04-09 08:11:56] cmb@php.net This behavior is a deliberate design decision[1], so I don't think this qualifies as bug; it's rather some form of error resilience. Of course, that behavior should be documented. If you, or anybody else, wants to have that behavior changed, please provide a pull request[2], or start discussion on the internals mailing list[3]; this bug tracker doesn't seem to be appropriate for this kind of feature request. [1] <https://github.com/php/php-src/blob/php-7.3.15/ext/standard/file.c#L2184-L2187> [2] <https://github.com/php/php-src/pulls> [3] <https://www.php.net/mailing-lists.php#internals> ------------------------------------------------------------------------ [2014-01-27 16:15:23] jameshfisher at gmail dot com Description: ------------ --- From manual page: http://www.php.net/splfileobject.fgetcsv --- Test script: --------------- Assume the file invalid.csv contains: blah,"blah Then run the script below: #!/usr/bin/env php5 <?php $s = new \SplFileObject('invalid.csv'); $r = NULL; while (!$s->eof()) { var_dump($s->fgetcsv(',','"')); } Expected result: ---------------- An error, signalled by FALSE, as described in the documentation for the method: $ ./test.php bool(false) Actual result: -------------- The cell in the file that does not have a closing quotation mark is treated as if EOF is the closing quotation mark. This is not compliant with the RFC: https://tools.ietf.org/html/rfc4180 $ ./test.php array(2) { [0]=> string(4) "blah" [1]=> string(5) "blah " } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66588&edit=1

« previous php.bugs (#236931) next »