Project

General

Profile

Actions

Bug #13149

closed

Ruby 2.4.0 の CSV の field_size_limit オプションで先読み文字数を制限できない

Added by koshigoe (Masataka SUZUKI) almost 8 years ago. Updated over 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]
[ruby-dev:49964]

Description

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

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

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>'

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

require 'csv'

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

__END__
"a","b"
"
2345
",""
$ ruby test.rb
["a", "b"]
["\n2345\n", ""]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0