Req #55413 [Opn->Csd]: str_getcsv doesnt remove escape characters

From: Date: Tue, 27 Jul 2021 10:06:11 +0000
Subject: Req #55413 [Opn->Csd]: str_getcsv doesnt remove escape characters
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235392@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55413&edit=1

 ID:                 55413
 Updated by:         cmb@php.net
 Reported by:        mathielen at gmail dot com
 Summary:            str_getcsv doesnt remove escape characters
-Status:             Open
+Status:             Closed
 Type:               Feature/Change Request
 Package:            Strings related
 Operating System:   ubuntu 11.04
 PHP Version:        5.3.6
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

The documentation has been updated a while ago[1].

Note that we can neither remove the escape parameter nor change
its default value.  As of PHP 7.4.0, it is possible to pass an
empty string as escape, which disables the proprietary escaping.

[1] <https://github.com/php/doc-en/commit/9421e06e34c689a3511a3fe889db295540bcf3a5>


Previous Comments:
------------------------------------------------------------------------
[2017-07-24 23:39:32] colinodell@php.net

Thanks for bringing the documentation to my attention - I hadn't realized that was there. 
Re-opening as requested.

------------------------------------------------------------------------
[2017-07-24 21:45:41] dan dot libby at gmail dot com

imho, this bug should not have been closed without at least updating the documentation to match what
the code actually does.

I just checked, and the online docs still say default="\\" without any comment that this
is basically a no-op and doesn't escape anything.

In order to achieve escaping then, one must use/have excel-style escaping in the source document AND
explicitly set escape='"'.

That seems totally broken and bizarre to me.

Further, one cannot always control the format of source document.  Consider if reading files from a
third-party.

I would urge you to reconsider and either fix docs or fix the function to be more useful.

------------------------------------------------------------------------
[2017-07-24 21:15:34] colinodell@php.net

Closing this because PHP does indeed have the ability to process escaped characters, but they must
be escaped the CSV way.

(Processing backslash-escaped characters would therefore be a feature change which may impact
backward compatibility.)

------------------------------------------------------------------------
[2017-07-24 21:03:09] colinodell@php.net

According to RFC 4180 Common Format and MIME Type for CSV Files:

> 7.  If double-quotes are used to enclose fields, then a double-quote
>     appearing inside a field must be escaped by preceding it with
>     another double quote.  For example:
>
>     "aaa","b""bb","ccc"

PHP does indeed support this escaping method which is common amongst most other CSV implementations:
https://3v4l.org/e0aX8

------------------------------------------------------------------------
[2014-10-24 17:08:16] desertshadow at gmail dot com

Has this bug really been open for 3 years? This is a pretty big bug, 
1) The docs are incorrect
2) The CSV parser isn't working correctly

I'm trying to escape a comma in a CSV string but it doesn't appear to be escaping
correctly.

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


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=55413


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


Thread (12 messages)

« previous php.bugs (#235392) next »