Index: lib/faster_csv.rb =================================================================== --- lib/faster_csv.rb (revision 5223) +++ lib/faster_csv.rb (working copy) @@ -1755,8 +1755,8 @@ # establish quoting rules do_quote = lambda do |field| - @quote_char + - String(field).gsub(@quote_char, @quote_char * 2) + + @quote_char + + stringify_field(field).gsub(@quote_char, @quote_char * 2) + @quote_char end @quote = if options.delete(:force_quotes) @@ -1766,7 +1766,7 @@ if field.nil? # represent +nil+ fields as empty unquoted fields "" else - field = String(field) # Stringify fields + field = stringify_field(field) # represent empty fields as empty quoted fields if field.empty? or field.count("\r\n#{@col_sep}#{@quote_char}").nonzero? @@ -1778,7 +1778,16 @@ end end end - + + # Stringify fields + def stringify_field(field) + if field.is_a?(String) + field.gsub("\r\n", "\n") + else + String(field) + end + end + # Pre-compiles parsers and stores them by name for access during reads. def init_parsers(options) # store the parser behaviors