diff --git a/lib/csv.rb b/lib/csv.rb index 914acb28c7..30e4b23586 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1656,7 +1656,7 @@ class CSV # The line number of the last row read from this file. Fields with nested # line-end characters will not affect this count. # - attr_reader :lineno + attr_reader :lineno, :line ### IO and StringIO Delegation ### @@ -1831,6 +1831,12 @@ class CSV return nil end + if in_extended_col + @line.concat(parse) + else + @line = parse.clone + end + parse.sub!(@parsers[:line_end], "") if csv.empty? diff --git a/test/csv/test_features.rb b/test/csv/test_features.rb index a558875522..65ef3da105 100755 --- a/test/csv/test_features.rb +++ b/test/csv/test_features.rb @@ -104,6 +104,20 @@ class TestCSV::Features < TestCSV assert_equal($/, CSV.new(STDERR).row_sep) end + def test_line + lines = [ + %Q(abc,def\n), + %Q(abc,"d\nef"\n), + %Q(abc,"d\r\nef"\n), + %Q(abc,"d\ref") + ] + csv = CSV.new(lines.join('')) + lines.each do |line| + csv.shift + assert_equal(line, csv.line) + end + end + def test_lineno assert_equal(5, @sample_data.lines.to_a.size)