ruby / csv

CSV Reading and Writing
https://ruby.github.io/csv/
BSD 2-Clause "Simplified" License
178 stars 113 forks source link

to_csv throws `ArgumentError: negative array size` when the limit is greater than the row size. #234

Closed sampatbadhe closed 2 years ago

sampatbadhe commented 2 years ago

I am adding test cases for recent changes for limit option added to to_csv method in https://github.com/ruby/csv/pull/229

  def test_to_csv_with_limit_set_to_negative_and_greater_than_the_number_of_rows
    csv = <<-CSV
A,B,C
1,2,3
4,5,6
7,8,9
    CSV

    assert_equal(<<-CSV, @table.to_csv(limit: -5))
    CSV
  end

When the limit is negative and greater than the row size then to_csv throws ArgumentError: negative array size

In above case, either it should return all the rows by setting limit to row size OR none(just headers when write_headers is true) by setting limit to zero.

kou commented 2 years ago

@ericgpks Do you want to work on this?

sampatbadhe commented 2 years ago

@kou @ericgpks I'd be happy to help here if you could help me with expectations.

kou commented 2 years ago

"None" is the expectation.

sampatbadhe commented 2 years ago

@kou @ericgpks I have made the changes in https://github.com/ruby/csv/pull/235 please review.

ericgpks commented 2 years ago

Thanks a lot. I will check the pr.

kou commented 2 years ago

Fixed by #235.