#60 Invalid output with NO_QUOTE_CHARACTER

closed-wont-fix
Scott Conway
None
5
2011-06-06
2011-02-08
Anonymous
No

Usage:
new CSVWriter(writer, DEFAULT_SEPARATOR, DEFAULT_QUOTE_CHARACTER)
Valid example output:
"a","b,b","c","d ""d"" d"

Usage:
new CSVWriter(writer, DEFAULT_SEPARATOR, NO_QUOTE_CHARACTER)
Invalid example output:
a,b,b,c,d ""d"" d

Expected output:
a,"b,b",c,"d ""d"" d"

Instead of writing invalid output the class should use the default quote character for the single values containing the separator or simply for the whole line.

Discussion

  • Scott Conway
    Scott Conway
    2011-04-07

    • assigned_to: nobody --> sconway
    • status: open --> open-wont-fix
     
  • Scott Conway
    Scott Conway
    2011-04-07

    Actually this is working as designed. By passing in the no_quote_character you are esentially saying the quote character is a legal character in your file that a) should be treated like any other character.

    If your fields actually has the separator character in them you should either use the default quote character or change your separator character.

    Sorry about that.

    :)

     
  • Scott Conway
    Scott Conway
    2011-06-06

    • status: open-wont-fix --> closed-wont-fix
     
  • Perhaps a better solution would be to add an "optimize output" flag or some such. So, if there are characters in the value that require quoting - such as the separator - the default quote is used. Otherwise the value is not quoted.

    By my understanding of CSV this is valid, and perhaps even encouraged.

     
  • Please disregard. The latest code has an "applyQuotesToAll" parameter, which looks like the equivalennt to what i proposed. My thanks to whoever added it.