From 1170b057e02cefd34b4ff88ee01369c91b16ae2d Mon Sep 17 00:00:00 2001 From: jeg2 Date: Tue, 1 Apr 2014 14:40:48 +0000 Subject: [PATCH] * lib/csv.rb: Symbol HeaderConverter: strip leading/trailing space. Reported by Skye Shaw [Fixes GH-575] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ lib/csv.rb | 4 ++-- test/csv/test_headers.rb | 7 ++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index d27882070d..ee351fa51a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Apr 1 11:39:57 2014 James Edward Gray II + + * lib/csv.rb: Symbol HeaderConverter: strip leading/trailing space. + Reported by Skye Shaw + [Fixes GH-575] + Tue Apr 1 11:34:04 2014 James Edward Gray II * lib/csv.rb: Don't attempt to convert nil headers. diff --git a/lib/csv.rb b/lib/csv.rb index 16a38a17cf..b8697fe1da 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -992,8 +992,8 @@ class CSV HeaderConverters = { downcase: lambda { |h| h.encode(ConverterEncoding).downcase }, symbol: lambda { |h| - h.encode(ConverterEncoding).downcase.gsub(/\s+/, "_"). - gsub(/\W+/, "").to_sym + h.encode(ConverterEncoding).downcase.strip.gsub(/\s+/, "_"). + gsub(/\W+/, "").to_sym } } diff --git a/test/csv/test_headers.rb b/test/csv/test_headers.rb index 94d5e9f03e..79ccd20c74 100755 --- a/test/csv/test_headers.rb +++ b/test/csv/test_headers.rb @@ -217,9 +217,10 @@ class TestCSV::Headers < TestCSV end def test_builtin_symbol_converter - csv = CSV.parse( "One,TWO Three", headers: true, - return_headers: true, - header_converters: :symbol ) + # Note that the trailing space is intentional + csv = CSV.parse( "One,TWO Three ", headers: true, + return_headers: true, + header_converters: :symbol ) assert_equal([:one, :two_three], csv.headers) end