mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
356b051532
commit
bde8a01d0a
4 changed files with 15 additions and 9 deletions
|
@ -1,3 +1,8 @@
|
|||
Sun Sep 28 09:05:53 2008 James Edward Gray II <jeg2@ruby-lang.org>
|
||||
|
||||
* 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 <tadf@dotrb.org>
|
||||
|
||||
* lib/mathn.rb: a hack to provide canonicalization. This must be
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(/^ +/, "")
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue