ruby-changes:33419
From: jeg2 <ko1@a...>
Date: Tue, 1 Apr 2014 23:40:53 +0900 (JST)
Subject: [ruby-changes:33419] jeg2:r45498 (trunk): * lib/csv.rb: Symbol HeaderConverter: strip leading/trailing space.
jeg2 2014-04-01 23:40:48 +0900 (Tue, 01 Apr 2014) New Revision: 45498 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45498 Log: * lib/csv.rb: Symbol HeaderConverter: strip leading/trailing space. Reported by Skye Shaw [Fixes GH-575] Modified files: trunk/ChangeLog trunk/lib/csv.rb trunk/test/csv/test_headers.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 45497) +++ ChangeLog (revision 45498) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Apr 1 11:39:57 2014 James Edward Gray II <james@g...> + + * 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 <james@g...> * lib/csv.rb: Don't attempt to convert nil headers. Index: lib/csv.rb =================================================================== --- lib/csv.rb (revision 45497) +++ lib/csv.rb (revision 45498) @@ -992,8 +992,8 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L992 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 } } Index: test/csv/test_headers.rb =================================================================== --- test/csv/test_headers.rb (revision 45497) +++ test/csv/test_headers.rb (revision 45498) @@ -217,9 +217,10 @@ class TestCSV::Headers < TestCSV https://github.com/ruby/ruby/blob/trunk/test/csv/test_headers.rb#L217 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/