Non-standard behaviour of writeCSVRecord/writeCSVFile
Summary
writeCSVRecord
and writeCSVFile
separate fields by commas, enclose them with a double quotation mark, and escape in fields with a backslash. The latter setting is non-standard; RFC 4180, section 2 item 7 specifies that a double quotation mark should be escaped by another double quotation mark.
This is not a big issue as you can use the *With
variants of these functions, but I would still expect the default to be to follow the standard.
Steps to reproduce
import StdEnv, Text.CSV
Start w
# (_,f,w) = fopen "x.csv" FWriteText w
# f = writeCSVRecord ["a\"b", "a\\b"] f
# (_,w) = fclose f w
= w
What is the current bug behavior?
- These functions escape
"
with\"
and\
with\\
. The content of x.csv is"a\"b","a\\b"
.
What is the expected correct behavior?
- These functions escape
"
with""
, and do not escape\
. The content of x.csv is"a""b","a\b"
.
Possible fixes
Simply replace the last argument to writeCSV{Record,File}With
.