Bug #76730 [Com]: fgetcsv don't parse correctly JSON in a cell

From: Date: Sat, 11 Aug 2018 15:50:58 +0000
Subject: Bug #76730 [Com]: fgetcsv don't parse correctly JSON in a cell
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216724@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76730&edit=1 ID: 76730 Comment by: spam2 at rhsoft dot net Reported by: alex at render dot es Summary: fgetcsv don't parse correctly JSON in a cell Status: Closed Type: Bug Package: *General Issues Operating System: centos 7, osx 10.13.6, debian 8 PHP Version: 7.1.20 Block user comment: N Private report: N New Comment: did you try to create a csv with fputcsv and look at the differences between that and you and crafted input? anyways, one would normale use base64 encoding to avoid such issues from start Previous Comments: ------------------------------------------------------------------------ [2018-08-11 15:42:41] alex at render dot es Thanks for your answers. the number of CSV '"' are correct (the CSV escape with '"'). The problem was with the escape character that need to be '"': fgetcsv($f, 0, ';', '"', '"') work ok. Is confusing because fgetcsv work with the JSON: "{""test"":""this is test""}" without change the default format: fgetcsv($f, 0) and in this case the escape is '"' not the default '\' Why... ?????? ------------------------------------------------------------------------ [2018-08-11 15:08:20] a at b dot c dot de I think you have too many '"' in your CSV. "{""test"":""this is \"test\"""}" ------------------------------------------------------------------------ [2018-08-11 15:05:01] a at b dot c dot de Are your parameters to fgetcsv correct? You're specifying " as the delimiter as the field delimiter but you're using it as the enclosure character. Also, fgetcsv() defaults to using \ as the escape character. ------------------------------------------------------------------------ [2018-08-11 14:59:36] alex at render dot es Is possible do the escape with the '"' and the error disappear ------------------------------------------------------------------------ [2018-08-11 14:20:03] alex at render dot es add more oses ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=76730 -- Edit this bug report at https://bugs.php.net/bug.php?id=76730&edit=1

« previous php.bugs (#216724) next »