Bug #4041

Array#to_csv generates invalid US-ASCII string

Added by akr (Akira Tanaka) about 10 years ago. Updated over 9 years ago.

Target version:
ruby -v:
ruby 1.9.3dev (2010-11-10 trunk 29738) [i686-linux]


I found Array#to_csv method generates a string with invalid encoding.

% ./ruby -rcsv -ve '
a = ["foo".force_encoding("US-ASCII"), "\u3042"]
p {|v| v.encoding }
s = a.to_csv
p s
p s.encoding'
ruby 1.9.3dev (2010-11-10 trunk 29738) [i686-linux]
[#Encoding:US-ASCII, #Encoding:UTF-8]

The array to convert to CSV using Array#to_csv contains US-ASCII string and
UTF-8 string.
But the result is US-ASCII string which contains 8-bit bytes.

I think the result should be UTF-8 string.
Tanaka Akira


Updated by naruse (Yui NARUSE) about 10 years ago

  • Category set to lib
  • Status changed from Open to Assigned
  • Assignee set to JEG2 (James Gray)
  • Priority changed from 3 to Normal
  • ruby -v set to ruby 1.9.3dev (2010-11-10 trunk 29738) [i686-linux]




Updated by JEG2 (James Gray) about 10 years ago

I agree that this is a problem. I will look into it.


Updated by JEG2 (James Gray) about 10 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r29808.
Akira, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


Also available in: Atom PDF