Project

General

Profile

Bug #13149

Updated by nobu (Nobuyoshi Nakada) almost 8 years ago

Ruby 2.4.0 から、指定文字数未満で例外が出る事も、指定文字数以上で例外が出ない事もあります。 

 以下、指定文字数未満で例外が出るケース。 

 ~~~ruby ~~~ 
 require 'csv' 

 CSV.new(DATA, field_size_limit: 4).each { |x| p x } 

 __END__ 
 "a","b" 
 " 
 2 
 ","" 
 ~~~ 

 ~~~ 
 $ ruby test.rb 
 ["a", "b"] 
 ~/.rbenv/versions/2.4.0/lib/ruby/2.4.0/csv.rb:1931:in `block in shift': Field size exceeded on line 2. (CSV::MalformedCSVError) 
         from ~/.rbenv/versions/2.4.0/lib/ruby/2.4.0/csv.rb:1828:in `loop' 
         from ~/.rbenv/versions/2.4.0/lib/ruby/2.4.0/csv.rb:1828:in `shift' 
         from ~/.rbenv/versions/2.4.0/lib/ruby/2.4.0/csv.rb:1770:in `each' 
         from test.rb:3:in `<main>' 
 ~~~ 

 以下、指定文字数以上で例外が出ないケース。 

 ~~~ruby ~~~ 
 require 'csv' 

 CSV.new(DATA, field_size_limit: 5).each { |x| p x } 

 __END__ 
 "a","b" 
 " 
 2345 
 ","" 
 ~~~ 

 ~~~ 
 $ ruby test.rb 
 ["a", "b"] 
 ["\n2345\n", ""] 
 ~~~

Back