#33847 [Bgs]: fgetcsv incorrectly treats backslash
| From: | vasilyev at math dot uchicago dot edu | Date: | Thu, 28 Jul 2005 23:05:43 +0000 |
| Subject: | #33847 [Bgs]: fgetcsv incorrectly treats backslash | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-82631@lists.php.net to get a copy of this message | ||
ID: 33847
User updated by: vasilyev at math dot uchicago dot edu
Reported By: vasilyev at math dot uchicago dot edu
Status: Bogus
Bug Type: Filesystem function related
Operating System: OS X (irrelevant)
PHP Version: 5.0.4
New Comment:
I understand your concern that changing the behavior might break BC.
However, not changing the behavior makes fgetcsv() not compatible with
other csv applications (gnumeric for example). I suggest to introduce
an option in php.ini that would make fgetcsv() work the old way.
Previous Comments:
------------------------------------------------------------------------
[2005-07-25 04:18:52] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
The current behaviour is based on how various csv parsers work, any
deviation from that would result in BC break. Therefor this
functionality is not going to change.
------------------------------------------------------------------------
[2005-07-25 01:00:00] vasilyev at math dot uchicago dot edu
Description:
------------
This has been already mentioned in several bugs, that were all
dismissed as bogus. Nevertheless, I believe there is a serious problem
with the way fgetcsv treats backslash.
Example:
"a\","b"
produces
Array
(
[0] => a\",b"
)
iliia@php.net says that this is an expected behavior since backslash is
an escaping character.
Well, if this were true then
"a\"b","c"
would give
Array
(
[0] => a"b
[1] => c
)
while in fact you get
Array
(
[0] => a\"b
[1] => c
)
Another scenario: what do you do if you want to have a backslash at the
end of a field (and let's say there are commas in that field, so we do
have to use quotes). Well the natural answer is to escape the
backslash:
"a\\","b"
but this would produce
Array
(
[0] => a\\
[1] => b
)
It seems that the only thing a backslash does is making fgetcsv() not
treat the following quote as an enclosure mark, without actually
stripping the backslash. This is not escaping.
There are two ways this can be fixed:
1.Make backslash an escaping character. This would further deviate
fgetcsv() parsing of CSV files from the wide-spread understanding of
what a CSV format is.
2.Treat backslash as any other character.
I would prefer the second choice.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33847&edit=1