php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76940 fgetcsv not correctly parsing fputcsv output
Submitted: 2018-09-27 05:44 UTC Modified: 2018-09-27 08:56 UTC
From: simon dot welsh at themarkagency dot com dot au Assigned: cmb (profile)
Status: Duplicate Package: *Directory/Filesystem functions
PHP Version: 7.3.0RC1 OS: macOS + Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: simon dot welsh at themarkagency dot com dot au
New email:
PHP Version: OS:

 

 [2018-09-27 05:44 UTC] simon dot welsh at themarkagency dot com dot au
Description:
------------
When a value passed to `fputcsv` ends with the escape character, `fgetcsv` (and `str_getcsv`) do not correctly parse it.

I'm not sure if this is an issue with `fputcsv` not escaping the escape character or `fgetcsv` not handling things properly.

Test script:
---------------
<?php

$input = array(1, 3, '3\\', 5, 3);
$f = fopen('php://temp,', 'w+');
fputcsv($f, $input);
rewind($f);
$output = stream_get_contents($f);

rewind($f);
var_dump($input, $output, str_getcsv($output), fgetcsv($f));
fclose($f);

Expected result:
----------------
I expect `$input` and the results from `str_getcsv` and `fgetcsv` to be the same

Actual result:
--------------
The final three fields, including separators, are parsed as a single field.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-27 08:56 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2018-09-27 08:56 UTC] cmb@php.net
Basically a duplicate of bug #74713.

As workaround you may be able to use "\0" as $escape parameter of
fgetcsv() and fputcsv().
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 07:01:33 2024 UTC