ruby-changes:16511
From: yugui <ko1@a...>
Date: Thu, 1 Jul 2010 11:05:39 +0900 (JST)
Subject: [ruby-changes:16511] Ruby:r28501 (ruby_1_9_2): merges r28431 and r28432 from trunk into ruby_1_9_2.
yugui 2010-07-01 11:05:16 +0900 (Thu, 01 Jul 2010) New Revision: 28501 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28501 Log: merges r28431 and r28432 from trunk into ruby_1_9_2. -- * lib/csv.rb: Fixing a bug that prevented CSV from parsing all multi-line fields correctly. Patch by Rob Biedenham. -- Fixing a spelling error. Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/lib/csv.rb branches/ruby_1_9_2/test/csv/test_csv_parsing.rb Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 28500) +++ ruby_1_9_2/ChangeLog (revision 28501) @@ -1,3 +1,8 @@ +Fri Jun 25 11:45:36 2010 James Edward Gray II <jeg2@r...> + + * lib/csv.rb: Fixing a bug that prevented CSV from parsing + all multi-line fields correctly. Patch by Rob Biedenharn. + Sat Jun 26 10:08:36 2010 Nobuyoshi Nakada <nobu@r...> * test/ruby/envutil.rb (EnvUtil#invoke_ruby): no needs to copy the Index: ruby_1_9_2/lib/csv.rb =================================================================== --- ruby_1_9_2/lib/csv.rb (revision 28500) +++ ruby_1_9_2/lib/csv.rb (revision 28501) @@ -198,7 +198,7 @@ # class CSV # The version of the installed library. - VERSION = "2.4.6".freeze + VERSION = "2.4.7".freeze # # A CSV::Row is part Array and part Hash. It retains an order for the fields @@ -1843,7 +1843,13 @@ end parts = parse.split(@col_sep, -1) - csv << nil if parts.empty? + if parts.empty? + if in_extended_col + csv[-1] << @col_sep # will be replaced with a @row_sep after the parts.each loop + else + csv << nil + end + end # This loop is the hot path of csv parsing. Some things may be non-dry # for a reason. Make sure to benchmark when refactoring. Index: ruby_1_9_2/test/csv/test_csv_parsing.rb =================================================================== --- ruby_1_9_2/test/csv/test_csv_parsing.rb (revision 28500) +++ ruby_1_9_2/test/csv/test_csv_parsing.rb (revision 28501) @@ -115,6 +115,22 @@ assert_equal(Array.new, CSV.parse_line("\n1,2,3\n")) end + def test_rob_edge_cases + [ [%Q{"a\nb"}, ["a\nb"]], + [%Q{"\n\n\n"}, ["\n\n\n"]], + [%Q{a,"b\n\nc"}, ['a', "b\n\nc"]], + [%Q{,"\r\n"}, [nil,"\r\n"]], + [%Q{,"\r\n."}, [nil,"\r\n."]], + [%Q{"a\na","one newline"}, ["a\na", 'one newline']], + [%Q{"a\n\na","two newlines"}, ["a\n\na", 'two newlines']], + [%Q{"a\r\na","one CRLF"}, ["a\r\na", 'one CRLF']], + [%Q{"a\r\n\r\na","two CRLFs"}, ["a\r\n\r\na", 'two CRLFs']], + [%Q{with blank,"start\n\nfinish"\n}, ['with blank', "start\n\nfinish"]], + ].each do |edge_case| + assert_equal(edge_case.last, CSV.parse_line(edge_case.first)) + end + end + def test_non_regex_edge_cases # An early version of the non-regex parser fails this test [ [ "foo,\"foo,bar,baz,foo\",\"foo\"", -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/