From: naruse@airemix•jp
To: ruby-dev@ruby-lang.org
Subject: [ruby-dev:50773] [Ruby trunk Bug#15521] encoding is missed when using `CSV.generate`
Date: Sat, 26 Jan 2019 08:02:53 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-76520.20190126080252.613d2ccadfcdb687@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15521.20190110062059@ruby-lang.org
Issue #15521 has been updated by naruse (Yui NARUSE).
Backport changed from 2.4: DONTNEED, 2.5: DONTNEED, 2.6: REQUIRED to 2.4: DONTNEED, 2.5: DONTNEED, 2.6: DONE
ruby_2_6 r66926 merged revision(s) 66922.
----------------------------------------
Bug #15521: encoding is missed when using `CSV.generate`
https://bugs.ruby-lang.org/issues/15521#change-76520
* Author: sue445 (Go Sueyoshi)
* Status: Closed
* Priority: Normal
* Assignee: kou (Kouhei Sutou)
* Target version:
* ruby -v: ruby 2.6.0p0
* Backport: 2.4: DONTNEED, 2.5: DONTNEED, 2.6: DONE
----------------------------------------
# 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/
prev parent reply other threads:[~2019-01-26 8:02 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 ` [ruby-dev:50756] [Ruby trunk Bug#15521][Closed] " kou
2019-01-10 6:57 ` [ruby-dev:50757] [Ruby trunk Bug#15521] " sue445fukuoka
2019-01-25 6:52 ` [ruby-dev:50770] " kou
2019-01-26 8:02 ` naruse [this message]
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-76520.20190126080252.613d2ccadfcdb687@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).