php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33179 backslash is not an escape character in correct CSV
Submitted: 2005-05-30 02:22 UTC Modified: 2005-06-09 03:13 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: fsb at thefsb dot org Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.10 OS: os x 10.3 and freebsd 5.3
Private report: No CVE-ID: None
 [2005-05-30 02:22 UTC] fsb at thefsb dot org
Description:
------------
why can i have a \ at the end of a field but not
if i wrap it in " field delimiters? e.g.

  abc,123\,abc       works fine but

  "abc","123\",abc   produces only two columns

this question has been asked before (#29278, #30476,
etc.) and iliaa@php.net rejects the bug as bogus. i 
don't agree. 

if this is not a bug then this unusual use of \ to 
escape only closing field delimiting double quotes 
but not escape any other instances of double qotes or 
(it would appear) any other character SHOULD be 
documented. it is not.

moreover this undocumented feature is not consistent 
with the specification of the CSV file format found 
here: http://www.creativyst.com/Doc/Articles/CSV/
CSV01.htm

this csv spec suggests that backslash has no special 
meaning in the CSV format at all. indeed, in all my 
tests, fgetcsv appears to accord it no special meaning 
_except_ in this one particular case.

such a surprising behaviour that deviates from common 
CSV file format conventions SHOULD be documented (or 
corrected).


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-31 01:18 UTC] 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

As far as PHP is concerned backslash is an escape characte, which makes the demonstrated behaviour expected.
 [2005-06-01 02:25 UTC] fsb at thefsb dot org
if backslash were an escape character to PHP then it 
would not appear in the parsed values from the following 
csv file:

abc,123,abc,123,abc,123
abc,\ 123,abc,123,abc,123
abc,123\ ,abc,123,abc,123
abc,123,abc\,123,abc,123
abc,123,\"abc",123,abc,123
abc,123,"a\""bc",123,abc,123
abc,123,"a"\"bc",123,abc,123
abc,123,"a""bc"\ ,123,abc,123

in every case above, the backslash preceeds a special 
caracter in the csv file format. if backshalsh were 
generally an escape character then in these positions it 
should be removed by the csv parser leaving the 
following character as literal.
 [2005-06-04 01:49 UTC] fsb at thefsb dot org
iliaa, please see my update from 6/1. i omitted to 
change the status to open when i submitted it.
 [2005-06-06 10:25 UTC] sniper@php.net
Check you magic_quotes_* settings in php.ini..

 [2005-06-09 03:13 UTC] fsb at thefsb dot org
snipper,

both are turned off.

since you changed the state back to bogus i assume that 
your note was not a request for more information about 
the bug. i suppose i should take the hint and just stop 
bothering people.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 16:01:29 2024 UTC