From f9a5335ed4f84e6e3ed23cb92966a36101d9d149 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 10 Jun 2014 01:57:10 +0000 Subject: csv.rb: honor encoding option * lib/csv.rb (CSV#<<): honor explicity given encoding. based on the patch by DAISUKE TANIWAKI at [ruby-core:62113]. [Bug #9766] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/csv/test_encodings.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/csv/test_encodings.rb b/test/csv/test_encodings.rb index 21b997c9ec..dc45692ce4 100755 --- a/test/csv/test_encodings.rb +++ b/test/csv/test_encodings.rb @@ -247,6 +247,14 @@ class TestCSV::Encodings < TestCSV assert_equal("UTF-8", data.to_csv.encoding.name) end + def test_explicit_encoding + bug9766 = '[ruby-core:62113] [Bug #9766]' + s = CSV.generate(encoding: "Windows-31J") do |csv| + csv << ["foo".force_encoding("ISO-8859-1"), "\u3042"] + end + assert_equal(["foo,\u3042\n".encode(Encoding::Windows_31J), Encoding::Windows_31J], [s, s.encoding], bug9766) + end + private def assert_parses(fields, encoding, options = { }) -- cgit v1.2.3