From bde8a01d0a8750f9e0a7728ee9ae3a0fea3001ed Mon Sep 17 00:00:00 2001 From: jeg2 Date: Sun, 28 Sep 2008 00:06:21 +0000 Subject: * lib/csv/csv.rb: Worked around some minor encoding changes in Ruby pointed out by Nobu. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ lib/csv.rb | 8 ++++---- test/csv/tc_csv_parsing.rb | 2 +- test/csv/tc_encodings.rb | 9 +++++---- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index e1e1783751..b840e97fae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Sep 28 09:05:53 2008 James Edward Gray II + + * lib/csv/csv.rb: Worked around some minor encoding changes in Ruby + pointed out by Nobu. + Sun Sep 28 08:37:12 2008 Tadayoshi Funaba * lib/mathn.rb: a hack to provide canonicalization. This must be diff --git a/lib/csv.rb b/lib/csv.rb index ccfa6ab42f..2cd4c17e98 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -199,7 +199,7 @@ require "stringio" # class CSV # The version of the installed library. - VERSION = "2.4.1".freeze + VERSION = "2.4.2".freeze # # A CSV::Row is part Array and part Hash. It retains an order for the fields @@ -831,7 +831,7 @@ class CSV # Shows the mode and size of this table in a US-ASCII String. def inspect - "#<#{self.class} mode:#{@mode} row_count:#{to_a.size}>" + "#<#{self.class} mode:#{@mode} row_count:#{to_a.size}>".encode("US-ASCII") end end @@ -1244,9 +1244,9 @@ class CSV encoding = options.delete(:encoding) str = "" if encoding - str.encode!(encoding) + str.force_encoding(encoding) elsif field = row.find { |f| not f.nil? } - str.encode!(String(field).encoding) + str.force_encoding(String(field).encoding) end (new(str, options) << row).string end diff --git a/test/csv/tc_csv_parsing.rb b/test/csv/tc_csv_parsing.rb index 635ae90531..6148d4a37d 100644 --- a/test/csv/tc_csv_parsing.rb +++ b/test/csv/tc_csv_parsing.rb @@ -141,7 +141,7 @@ class TestCSVParsing < Test::Unit::TestCase assert_equal( "Unquoted fields do not allow \\r or \\n (line 4).", $!.message ) end - + assert_raise(CSV::MalformedCSVError) { CSV.parse_line('1,2,"3...') } bad_data = <<-END_DATA.gsub(/^ +/, "") diff --git a/test/csv/tc_encodings.rb b/test/csv/tc_encodings.rb index 677ada3a14..6f88d089ea 100644 --- a/test/csv/tc_encodings.rb +++ b/test/csv/tc_encodings.rb @@ -207,8 +207,8 @@ class TestEncodings < Test::Unit::TestCase # writing to files data = encode_ary([%w[abc d,ef], %w[123 456 ]], encoding) - CSV.open(@temp_csv_path, "wb:#{encoding.name}") do |csv| - data.each { |row| csv << row } + CSV.open(@temp_csv_path, "wb:#{encoding.name}") do |f| + data.each { |row| f << row } end assert_equal(data, CSV.read(@temp_csv_path, :encoding => encoding.name)) end @@ -221,8 +221,9 @@ class TestEncodings < Test::Unit::TestCase fields = encode_ary(fields, encoding) parsed = CSV.parse(ary_to_data(fields, options), options) assert_equal(fields, parsed) - assert( parsed.flatten.all? { |field| field.encoding == encoding }, - "Fields were transcoded." ) + parsed.flatten.each_with_index do |field, i| + assert_equal(encoding, field.encoding, "Field[#{i + 1}] was transcoded.") + end end def encode_ary(ary, encoding) -- cgit v1.2.3