mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
7afe174b9e
commit
b028e8d45d
3 changed files with 15 additions and 3 deletions
|
@ -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]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue