[前][次][番号順一覧][スレッド一覧]

ruby-changes:33418

From: jeg2 <ko1@a...>
Date: Tue, 1 Apr 2014 23:35:08 +0900 (JST)
Subject: [ruby-changes:33418] jeg2:r45497 (trunk): * lib/csv.rb: Don't attempt to convert nil headers.

jeg2	2014-04-01 23:35:03 +0900 (Tue, 01 Apr 2014)

  New Revision: 45497

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45497

  Log:
    * lib/csv.rb: Don't attempt to convert nil headers.
      Reported by Skye Shaw

  Modified files:
    trunk/ChangeLog
    trunk/lib/csv.rb
    trunk/test/csv/test_headers.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45496)
+++ ChangeLog	(revision 45497)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Apr  1 11:34:04 2014  James Edward Gray II  <james@g...>
+
+	* lib/csv.rb: Don't attempt to convert nil headers.
+	  Reported by Skye Shaw
+
 Tue Apr  1 17:29:35 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* tool/config_files.rb (ConfigFiles.download): show failed URI.
Index: lib/csv.rb
===================================================================
--- lib/csv.rb	(revision 45496)
+++ lib/csv.rb	(revision 45497)
@@ -2168,6 +2168,7 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L2168
 
     fields.map.with_index do |field, index|
       converters.each do |converter|
+        break if field.nil?
         field = if converter.arity == 1  # straight field converter
           converter[field]
         else                             # FieldInfo converter
Index: test/csv/test_headers.rb
===================================================================
--- test/csv/test_headers.rb	(revision 45496)
+++ test/csv/test_headers.rb	(revision 45497)
@@ -223,6 +223,13 @@ class TestCSV::Headers < TestCSV https://github.com/ruby/ruby/blob/trunk/test/csv/test_headers.rb#L223
     assert_equal([:one, :two_three], csv.headers)
   end
 
+  def test_builtin_converters_with_blank_header
+    csv = CSV.parse( "one,,three", headers:           true,
+                                   return_headers:    true,
+                                   header_converters: [:downcase, :symbol] )
+    assert_equal([:one, nil, :three], csv.headers)
+  end
+
   def test_custom_converter
     converter = lambda { |header| header.tr(" ", "_") }
     csv       = CSV.parse( "One,TWO Three",

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]