1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

merge revision(s) 57406: [Backport #13149]

csv.rb: fix field_size_limit check

	* lib/csv.rb (CSV#shift): the last column is an Array in extended
	  column since r55985.  [ruby-dev:49964] [Bug #13149]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@57868 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2017-03-11 17:45:18 +00:00
parent 2ca56375fa
commit f1c8f49723
3 changed files with 24 additions and 2 deletions

View file

@ -1927,7 +1927,7 @@ class CSV
if @io.eof?
raise MalformedCSVError,
"Unclosed quoted field on line #{lineno + 1}."
elsif @field_size_limit and csv.last.size >= @field_size_limit
elsif @field_size_limit and csv.last.sum(&:size) >= @field_size_limit
raise MalformedCSVError, "Field size exceeded on line #{lineno + 1}."
end
# otherwise, we need to loop and pull some more data to complete the row

View file

@ -209,6 +209,28 @@ class TestCSV::Parsing < TestCSV
field_size_limit: 2048 )
end
def test_field_size_limit_in_extended_column_not_exceeding
data = <<~DATA
"a","b"
"
2
",""
DATA
assert_nothing_raised(CSV::MalformedCSVError) do
CSV.parse(data, field_size_limit: 4)
end
end
def test_field_size_limit_in_extended_column_exceeding
data = <<~DATA
"a","b"
"
2345
",""
DATA
assert_parse_errors_out(data, field_size_limit: 5)
end
private
def assert_parse_errors_out(*args)

View file

@ -1,6 +1,6 @@
#define RUBY_VERSION "2.4.0"
#define RUBY_RELEASE_DATE "2017-03-12"
#define RUBY_PATCHLEVEL 33
#define RUBY_PATCHLEVEL 34
#define RUBY_RELEASE_YEAR 2017
#define RUBY_RELEASE_MONTH 3