comma-csv/comma

Fields with line breaks \n

Startouf opened this issue · 1 comments

I need to export text fields that contain several line breaks \n. They are not escaped and when transforming to csv, they generate extra rows.

model Profile
  field :description
  # Sample description
  # "Hello,\n I'm here to destroy your CSV export 3:D"
end

Is there a way to escape them ? Or should I just define a description_escaped method that would substitute those \n by another separator ?

Passing force_quotes: true when you call to_comma might solve issue. According RFC 4180,

 6.  Fields containing line breaks (CRLF), double quotes, and commas
     should be enclosed in double-quotes.  For example:

     "aaa","b CRLF
     bb","ccc" CRLF
     zzz,yyy,xxx