ruby-changes:46628
From: hsbt <ko1@a...>
Date: Tue, 16 May 2017 18:17:17 +0900 (JST)
Subject: [ruby-changes:46628] hsbt:r58743 (trunk): Added accessor of original line when parsing.
hsbt 2017-05-16 18:17:09 +0900 (Tue, 16 May 2017) New Revision: 58743 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58743 Log: Added accessor of original line when parsing. [Feature #11865][ruby-core:72452][fix GH-1170] Modified files: trunk/lib/csv.rb trunk/test/csv/test_features.rb Index: lib/csv.rb =================================================================== --- lib/csv.rb (revision 58742) +++ lib/csv.rb (revision 58743) @@ -1656,7 +1656,7 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L1656 # 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 https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L1831 return nil end + if in_extended_col + @line.concat(parse) + else + @line = parse.clone + end + parse.sub!(@parsers[:line_end], "") if csv.empty? Index: test/csv/test_features.rb =================================================================== --- test/csv/test_features.rb (revision 58742) +++ test/csv/test_features.rb (revision 58743) @@ -104,6 +104,20 @@ class TestCSV::Features < TestCSV https://github.com/ruby/ruby/blob/trunk/test/csv/test_features.rb#L104 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/