mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/csv.rb: Fixed a bug in read_to_char() that would slurp
whole files if the encoding was invalid. It will now read up to 10 bytes ahead to find a valid character boundary or give up. [ruby-core:19465] * test/csv/test_features.rb, test/csv/test_table.rb, test/csv/test_row.rb: Loosened some tests to check for a compatible? Encoding instea of an exact Encoding. [ruby-core:19470] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7222e82a8b
commit
dfda5877ca
5 changed files with 33 additions and 14 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Sat Oct 25 09:54:10 2008 James Edward Gray II <jeg2@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/csv.rb: Fixed a bug in read_to_char() that would slurp
|
||||||
|
whole files if the encoding was invalid. It will now read
|
||||||
|
up to 10 bytes ahead to find a valid character boundary or
|
||||||
|
give up. [ruby-core:19465]
|
||||||
|
* test/csv/test_features.rb, test/csv/test_table.rb, test/csv/test_row.rb:
|
||||||
|
Loosened some tests to check for a compatible? Encoding instea
|
||||||
|
of an exact Encoding. [ruby-core:19470]
|
||||||
|
|
||||||
Sat Oct 25 07:42:49 2008 Eric Hodel <drbrain@segment7.net>
|
Sat Oct 25 07:42:49 2008 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
* lib/rdoc*: Update to RDoc 2.2.2 r192.
|
* lib/rdoc*: Update to RDoc 2.2.2 r192.
|
||||||
|
|
19
lib/csv.rb
19
lib/csv.rb
|
@ -199,7 +199,7 @@ require "stringio"
|
||||||
#
|
#
|
||||||
class CSV
|
class CSV
|
||||||
# The version of the installed library.
|
# The version of the installed library.
|
||||||
VERSION = "2.4.3".freeze
|
VERSION = "2.4.4".freeze
|
||||||
|
|
||||||
#
|
#
|
||||||
# A CSV::Row is part Array and part Hash. It retains an order for the fields
|
# A CSV::Row is part Array and part Hash. It retains an order for the fields
|
||||||
|
@ -1551,7 +1551,7 @@ class CSV
|
||||||
end
|
end
|
||||||
@encoding ||= Encoding.default_internal || Encoding.default_external
|
@encoding ||= Encoding.default_internal || Encoding.default_external
|
||||||
#
|
#
|
||||||
# prepare for build safe regular expressions in the target encoding,
|
# prepare for building safe regular expressions in the target encoding,
|
||||||
# if we can transcode the needed characters
|
# if we can transcode the needed characters
|
||||||
#
|
#
|
||||||
@re_esc = "\\".encode(@encoding) rescue ""
|
@re_esc = "\\".encode(@encoding) rescue ""
|
||||||
|
@ -2251,10 +2251,11 @@ class CSV
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Reads at least +bytes+ from <tt>@io</tt>, but will read on until the data
|
# Reads at least +bytes+ from <tt>@io</tt>, but will read up 10 bytes ahead if
|
||||||
# read is valid in the ecoding of that data. This should ensure that it is
|
# needed to ensure the data read is valid in the ecoding of that data. This
|
||||||
# safe to use regular expressions on the read data. The read data will be
|
# should ensure that it is safe to use regular expressions on the read data,
|
||||||
# returned in <tt>@encoding</tt>.
|
# unless it is actually a broken encoding. The read data will be returned in
|
||||||
|
# <tt>@encoding</tt>.
|
||||||
#
|
#
|
||||||
def read_to_char(bytes)
|
def read_to_char(bytes)
|
||||||
return "" if @io.eof?
|
return "" if @io.eof?
|
||||||
|
@ -2264,10 +2265,12 @@ class CSV
|
||||||
raise unless encoded.valid_encoding?
|
raise unless encoded.valid_encoding?
|
||||||
return encoded
|
return encoded
|
||||||
rescue # encoding error or my invalid data raise
|
rescue # encoding error or my invalid data raise
|
||||||
if @io.eof?
|
if @io.eof? or data.size >= bytes + 10
|
||||||
return data
|
return data
|
||||||
else
|
else
|
||||||
data += @io.read(1) until data.valid_encoding? or @io.eof?
|
data += @io.read(1) until data.valid_encoding? or
|
||||||
|
@io.eof? or
|
||||||
|
data.size >= bytes + 10
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -250,9 +250,11 @@ class TestCSVFeatures < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_inspect_is_ascii_8bit_encoded
|
def test_inspect_encoding_is_ascii_compatible
|
||||||
CSV.new("one,two,three\n1,2,3\n".encode("UTF-16BE")) do |csv|
|
CSV.new("one,two,three\n1,2,3\n".encode("UTF-16BE")) do |csv|
|
||||||
assert_equal("ASCII-8BIT", csv.inspect.encoding.name)
|
assert( Encoding.compatible?( Encoding.find("US-ASCII"),
|
||||||
|
csv.inspect.encoding ),
|
||||||
|
"inspect() was not ASCII compatible." )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -296,8 +296,10 @@ class TestCSVRow < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_inspect_is_ascii_8bit_encoded
|
def test_inspect_encoding_is_ascii_compatible
|
||||||
assert_equal("ASCII-8BIT", @row.inspect.encoding.name)
|
assert( Encoding.compatible?( Encoding.find("US-ASCII"),
|
||||||
|
@row.inspect.encoding ),
|
||||||
|
"inspect() was not ASCII compatible." )
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_inspect_shows_symbol_headers_as_bare_attributes
|
def test_inspect_shows_symbol_headers_as_bare_attributes
|
||||||
|
|
|
@ -400,7 +400,9 @@ class TestCSVTable < Test::Unit::TestCase
|
||||||
assert(str.include?("mode:#{@table.mode}"), "Mode not shown.")
|
assert(str.include?("mode:#{@table.mode}"), "Mode not shown.")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_inspect_is_us_ascii_encoded
|
def test_inspect_encoding_is_ascii_compatible
|
||||||
assert_equal("US-ASCII", @table.inspect.encoding.name)
|
assert( Encoding.compatible?( Encoding.find("US-ASCII"),
|
||||||
|
@table.inspect.encoding ),
|
||||||
|
"inspect() was not ASCII compatible." )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue