diff options
-rw-r--r-- | lib/csv.rb | 2 | ||||
-rwxr-xr-x | test/csv/test_csv_parsing.rb | 22 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 24 insertions, 2 deletions
diff --git a/lib/csv.rb b/lib/csv.rb index 03b87983e6..914acb28c7 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -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 diff --git a/test/csv/test_csv_parsing.rb b/test/csv/test_csv_parsing.rb index ff3d65fd24..547e70e933 100755 --- a/test/csv/test_csv_parsing.rb +++ b/test/csv/test_csv_parsing.rb @@ -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) @@ -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 |