From abf32b607e2cfe30471e32622d6b38889db59537 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Sat, 21 Dec 2024 17:48:04 +0900 Subject: [PATCH] Fix a parse bug with a quoted line with col_sep and an empty line GitHub: fix GH-324 This is introduced by bb93c289a529c77b5d5a8788dd8fdc03052216fc. We can't reuse `row` in this case because `row` is used for the next row. Reported by stoodfarback. Thanks!!! --- lib/csv/parser.rb | 2 +- test/csv/parse/test_general.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/csv/parser.rb b/lib/csv/parser.rb index 1e8a3c20..977ec235 100644 --- a/lib/csv/parser.rb +++ b/lib/csv/parser.rb @@ -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 diff --git a/test/csv/parse/test_general.rb b/test/csv/parse/test_general.rb index a565ff2e..7ec0994e 100644 --- a/test/csv/parse/test_general.rb +++ b/test/csv/parse/test_general.rb @@ -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 {