Bug #75418 [Opn->Dup]: fputcsv() escape parameter meaningless

From: Date: Thu, 15 Feb 2018 13:22:59 +0000
Subject: Bug #75418 [Opn->Dup]: fputcsv() escape parameter meaningless
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213970@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75418&edit=1

 ID:                 75418
 Updated by:         cmb@php.net
 Reported by:        phofstetter at sensational dot ch
 Summary:            fputcsv() escape parameter meaningless
-Status:             Open
+Status:             Duplicate
 Type:               Bug
 Package:            Filesystem function related
 Operating System:   macOS, Linux
 PHP Version:        7.2.0RC4
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Closing as duplicate of bug #43225.


Previous Comments:
------------------------------------------------------------------------
[2017-10-24 17:32:41] cmb@php.net

> It looks like that parameter is meaningless though as of all the
> possible values passed in, only " really does something […]

That's not quite right, see
<https://externals.io/message/100729#100729>,
for instance.

> […] and what it does is break the CSV encoding.

Indeed, using the $escape parameter with fputcsv() can easily
produce non-standard CSV (if there were such a standard).
Frankly, I do not know which use-case has been targetted by
introducing the $escape parameter.

------------------------------------------------------------------------
[2017-10-23 13:59:31] phofstetter at sensational dot ch

Description:
------------
Since 5.4.4 there's  an escape_char parameter that's defaulting to \. 

It looks like that parameter is meaningless though as of all the possible values passed in, only
" really does something and what it does is break the CSV encoding.

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

$fh = fopen('php://stdout', 'w');
fputcsv($fh, ['using default', 'a,"b'], ',', '"');
fputcsv($fh, ['using "      ', 'a,"b'], ',',
'"', '"');
fputcsv($fh, ['using x      ', 'a,"b'], ',', '"',
'x');
fputcsv($fh, ['using \\      ', 'a,"b'], ',', '"',
'\\');

Expected result:
----------------
"using default","a,\"b"
"using "      ","a,""b"
"using x      ","a,x"b"
"using \      ","a,\"b"

Actual result:
--------------
"using default","a,""b"
"using "      ","a,"b"
"using x      ","a,""b"
"using \      ","a,""b"


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=75418&edit=1


Thread (3 messages)

« previous php.bugs (#213970) next »