ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
From: kou@cozmixng•org
To: ruby-dev@ruby-lang.org
Subject: [ruby-dev:50756] [Ruby trunk Bug#15521][Closed] encoding is missed when using `CSV.generate`
Date: Thu, 10 Jan 2019 06:34:10 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-76180.20190110063409.ac469ffeb741b189@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15521.20190110062059@ruby-lang.org

Issue #15521 has been updated by kou (Kouhei Sutou).

Status changed from Open to Closed
Assignee set to kou (Kouhei Sutou)

Thanks for your report.
This has been fixed at master: https://github.com/ruby/csv/issues/62

I'll release a new version in a few weeks. Could you try the release (or master) again?

----------------------------------------
Bug #15521: encoding is missed when using `CSV.generate`
https://bugs.ruby-lang.org/issues/15521#change-76180

* Author: sue445 (Go Sueyoshi)
* Status: Closed
* Priority: Normal
* Assignee: kou (Kouhei Sutou)
* Target version: 
* ruby -v: ruby 2.6.0p0
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
# Sample code
~~~ ruby
require "csv"

rows = [
  ["a", "b", "c", "d", "e"],
  ["あ", "い", "う", "え", "お"],
]

str = CSV.generate do |csv|
  rows.each do |row|
    csv << row
  end
end

p str
p str.encoding
~~~


# Expected (on Ruby 2.5.3)
~~~
$ ruby csv_generate.rb
"a,b,c,d,e\nあ,い,う,え,お\n"
#<Encoding:UTF-8>
~~~

# Actual (on Ruby 2.6.0)
~~~
$ ruby csv_generate.rb
"a,b,c,d,e\n\xE3\x81\x82,\xE3\x81\x84,\xE3\x81\x86,\xE3\x81\x88,\xE3\x81\x8A\n"
#<Encoding:ASCII-8BIT>
~~~


This behavior is same to ruby-trunk

~~~
$ ruby -v
ruby 2.7.0dev (2019-01-10 trunk 66768) [x86_64-darwin17]
~~~

# Workaround
Use `force_encoding`

~~~ruby
require "csv"

rows = [
  ["a", "b", "c", "d", "e"],
  ["あ", "い", "う", "え", "お"],
]

str = CSV.generate do |csv|
  rows.each do |row|
    csv << row
  end
end.force_encoding("UTf-8")

p str
p str.encoding
~~~

This works, but little dirty...



-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2019-01-10  6:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-15521.20190110062059@ruby-lang.org>
2019-01-10  6:21 ` [ruby-dev:50755] [Ruby trunk Bug#15521] encoding is missed when using `CSV.generate` sue445fukuoka
2019-01-10  6:34 ` kou [this message]
2019-01-10  6:57 ` [ruby-dev:50757] " sue445fukuoka
2019-01-25  6:52 ` [ruby-dev:50770] " kou
2019-01-26  8:02 ` [ruby-dev:50773] " naruse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-76180.20190110063409.ac469ffeb741b189@ruby-lang.org \
    --to=ruby-dev@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).