ruby-changes:46629
From: hsbt <ko1@a...>
Date: Tue, 16 May 2017 18:32:38 +0900 (JST)
Subject: [ruby-changes:46629] hsbt:r58744 (trunk): Strip punctuation from CSV headers in symbol converter.
hsbt 2017-05-16 18:32:32 +0900 (Tue, 16 May 2017) New Revision: 58744 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58744 Log: Strip punctuation from CSV headers in symbol converter. Patch by @cllns. [Fix GH-957] Modified files: trunk/lib/csv.rb trunk/test/csv/test_headers.rb Index: lib/csv.rb =================================================================== --- lib/csv.rb (revision 58743) +++ lib/csv.rb (revision 58744) @@ -1014,8 +1014,8 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L1014 HeaderConverters = { downcase: lambda { |h| h.encode(ConverterEncoding).downcase }, symbol: lambda { |h| - h.encode(ConverterEncoding).downcase.strip.gsub(/\s+/, "_"). - gsub(/\W+/, "").to_sym + h.encode(ConverterEncoding).downcase.gsub(/[^[\s\w]]+/, "").strip. + gsub(/\s+/, "_").to_sym } } Index: test/csv/test_headers.rb =================================================================== --- test/csv/test_headers.rb (revision 58743) +++ test/csv/test_headers.rb (revision 58744) @@ -225,6 +225,13 @@ class TestCSV::Headers < TestCSV https://github.com/ruby/ruby/blob/trunk/test/csv/test_headers.rb#L225 assert_equal([:one, :two_three], csv.headers) end + def test_builtin_symbol_converter_with_punctuation + csv = CSV.parse( "One, Two & Three ($)", headers: true, + return_headers: true, + header_converters: :symbol ) + 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, -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/