Project

General

Profile

Actions

Bug #4041

closed

Array#to_csv generates invalid US-ASCII string

Added by akr (Akira Tanaka) over 13 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 1.9.3dev (2010-11-10 trunk 29738) [i686-linux]
Backport:
[ruby-core:33135]

Description

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

% ./ruby -rcsv -ve '
a = ["foo".force_encoding("US-ASCII"), "\u3042"]
p a.map {|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]
"foo,\xE3\x81\x82\n"
#Encoding:US-ASCII

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
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0