summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-17 15:03:25 +0000
committerjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-17 15:03:25 +0000
commitb028e8d45d90bec5ee5bcc9c4e42adc96f5d6f14 (patch)
tree08e8078c75f1a5082c33554ebe5f0492df9cbb8a
parent7afe174b9e7a4c977df77163ffdfae98090371a3 (diff)
* lib/csv.rb: Upgrading output encoding with ASCII content
as needed. [ruby-core:33229] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--lib/csv.rb3
-rw-r--r--test/csv/test_encodings.rb8
3 files changed, 15 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 3b44fa5..1de90f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Nov 18 00:02:17 2010 James Edward Gray II <jeg2@ruby-lang.org>
+
+ * lib/csv.rb: Upgrading output encoding with ASCII content
+ as needed. [ruby-core:33229]
+
Wed Nov 17 23:19:21 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/configure.bat: remove quotes from arguments to be quoted.
@@ -43,7 +48,7 @@ Wed Nov 17 09:49:10 2010 NARUSE, Yui <naruse@ruby-lang.org>
* enc/euc_jp.c (property_name_to_ctype): ditto.
-Tue Nov 17 08:54:04 2010 James Edward Gray II <jeg2@ruby-lang.org>
+Wed Nov 17 08:54:04 2010 James Edward Gray II <jeg2@ruby-lang.org>
* lib/csv.rb: Upgrading output encoding as needed. [ruby-core:33135]
diff --git a/lib/csv.rb b/lib/csv.rb
index fe73090..31388bc 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -1715,8 +1715,7 @@ class CSV
output = row.map(&@quote).join(@col_sep) + @row_sep # quote and separate
if @io.is_a?(StringIO) and
output.encoding != raw_encoding and
- ( compatible_encoding = Encoding.compatible?( @io.string.encoding,
- output.encoding ) )
+ (compatible_encoding = Encoding.compatible?(@io.string, output))
@io = StringIO.new(@io.string.force_encoding(compatible_encoding))
@io.seek(0, IO::SEEK_END)
end
diff --git a/test/csv/test_encodings.rb b/test/csv/test_encodings.rb
index 8d7de2e..8470286 100644
--- a/test/csv/test_encodings.rb
+++ b/test/csv/test_encodings.rb
@@ -225,6 +225,14 @@ class TestEncodings < Test::Unit::TestCase
assert_equal("UTF-8", data.join.encoding.name)
assert_equal("UTF-8", data.to_csv.encoding.name)
end
+
+ def test_encoding_is_upgraded_for_ascii_content_during_writing_as_needed
+ data = ["foo".force_encoding("ISO-8859-1"), "\u3042"]
+ assert_equal("ISO-8859-1", data.first.encoding.name)
+ assert_equal("UTF-8", data.last.encoding.name)
+ assert_equal("UTF-8", data.join.encoding.name)
+ assert_equal("UTF-8", data.to_csv.encoding.name)
+ end
private