1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Strip punctuation from CSV headers in symbol converter.

Patch by @cllns. [Fix GH-957]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2017-05-16 09:32:32 +00:00
parent 3b77cb2a64
commit 87acdae43d
2 changed files with 9 additions and 2 deletions

View file

@ -1014,8 +1014,8 @@ class CSV
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
}
}

View file

@ -225,6 +225,13 @@ class TestCSV::Headers < TestCSV
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,