summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-04-01 14:35:03 +0000
committerjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-04-01 14:35:03 +0000
commit7c4d4e1eb2897cec295ea9316835fc3cfef96d6d (patch)
treeea5c883071e0e42591b68b01d380d13a165376f2
parent86034eafb2fb38ad28b181e39f4dd7514260fe0b (diff)
downloadruby-7c4d4e1eb2897cec295ea9316835fc3cfef96d6d.tar.gz
* lib/csv.rb: Don't attempt to convert nil headers.
Reported by Skye Shaw git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--lib/csv.rb1
-rwxr-xr-xtest/csv/test_headers.rb7
3 files changed, 13 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 4cae32d96d..d27882070d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Apr 1 11:34:04 2014 James Edward Gray II <james@graysoftinc.com>
+
+ * lib/csv.rb: Don't attempt to convert nil headers.
+ Reported by Skye Shaw
+
Tue Apr 1 17:29:35 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* tool/config_files.rb (ConfigFiles.download): show failed URI.
diff --git a/lib/csv.rb b/lib/csv.rb
index 2326792cd7..16a38a17cf 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -2168,6 +2168,7 @@ class CSV
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
diff --git a/test/csv/test_headers.rb b/test/csv/test_headers.rb
index 069526fc03..94d5e9f03e 100755
--- a/test/csv/test_headers.rb
+++ b/test/csv/test_headers.rb
@@ -223,6 +223,13 @@ class TestCSV::Headers < TestCSV
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",