Skip to content

Commit

Permalink
Fix a parse bug with a quoted line with col_sep and an empty line
Browse files Browse the repository at this point in the history
GitHub: fix GH-324

This is introduced by bb93c28.

We can't reuse `row` in this case because `row` is used for the next
row.

Reported by stoodfarback. Thanks!!!
  • Loading branch information
kou committed Dec 21, 2024
1 parent 61b7237 commit abf32b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/csv/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ def parse_quotable_robust(&block)
quoted_fields << @quoted_column_value
elsif parse_row_end
if row.empty? and value.nil?
emit_row(row, &block) unless @skip_blanks
emit_row([], &block) unless @skip_blanks
else
row << value
quoted_fields << @quoted_column_value
Expand Down
9 changes: 9 additions & 0 deletions test/csv/parse/test_general.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,15 @@ def test_seeked_string_io
CSV.new(input_with_bom).each.to_a)
end

def test_quoted_col_sep_and_empty_line
assert_equal([["one,"], [], ["three"]],
CSV.parse(<<-CSV))
"one,"
"three"
CSV
end

private

{
Expand Down

0 comments on commit abf32b6

Please sign in to comment.