Re: fgetcsv incompatible with fputcsv

From: Date: Fri, 21 Nov 2014 18:44:21 +0000
Subject: Re: fgetcsv incompatible with fputcsv
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-79094@lists.php.net to get a copy of this message
Am 21.11.2014 um 02:53 schrieb Tjerk Meesters: >> On 21 Nov 2014, at 02:14, Christoph Becker <cmbecker69@gmx.de> wrote: >> >> Apparently, there is a somewhat hidden bug, see >> <http://3v4l.org/El5Xs> >> for a simplified test script. The expected result is >> >> string(14) ""a""b","a\""b"" >> >> or maybe >> >> string(14) ""a\"b","a\\"b"" >> >> The actual result makes no sense to me, even though str_getcsv() parses >> it "correctly”. > > That works exactly for the wrong reasons: > 1) upon seeing an escape character fgetcsv() will print that and the following character > 2) fputcsv() actually accepts an escape character too (despite what the documentation says) but > treats it in the wrong way by not escaping that and the following character Ah, I see, thanks for the explanation. Apparently[1], the $escape parameter to fputcsv() has been added in PHP 5.5. I have made a respective edit at edit.php.net. BTW: wouldn't it be reasonable to also add the $escape parameter to SplFileObject::fputcsv()? For now one has to use SplFileObject::setCsvControl(). > The expected output, based on the given code should (imo) be: > > string(15) ""a\"b","a\\\"b"" > > Or: if the escape character is a double quote: > > string(15) “"a""b",”a\""b”” ACK. (Even though that would be a BC break.) > Unfortunately I can’t satisfy all the related bug reports, some decision of “correctness” > needs to be made in the form of an RFC. ACK. Thanks for taking the time. :) [1] <http://lxr.php.net/xref/PHP_5_5/ext/standard/file.c#1810> vs <http://lxr.php.net/xref/PHP_5_4/ext/standard/file.c#1807> -- Christoph M. Becker

« previous php.internals (#79094) next »