mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
7c4d4e1eb2
commit
1170b057e0
3 changed files with 12 additions and 5 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Tue Apr 1 11:39:57 2014 James Edward Gray II <james@graysoftinc.com>
|
||||||
|
|
||||||
|
* 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@graysoftinc.com>
|
Tue Apr 1 11:34:04 2014 James Edward Gray II <james@graysoftinc.com>
|
||||||
|
|
||||||
* lib/csv.rb: Don't attempt to convert nil headers.
|
* lib/csv.rb: Don't attempt to convert nil headers.
|
||||||
|
|
|
@ -992,8 +992,8 @@ class CSV
|
||||||
HeaderConverters = {
|
HeaderConverters = {
|
||||||
downcase: lambda { |h| h.encode(ConverterEncoding).downcase },
|
downcase: lambda { |h| h.encode(ConverterEncoding).downcase },
|
||||||
symbol: lambda { |h|
|
symbol: lambda { |h|
|
||||||
h.encode(ConverterEncoding).downcase.gsub(/\s+/, "_").
|
h.encode(ConverterEncoding).downcase.strip.gsub(/\s+/, "_").
|
||||||
gsub(/\W+/, "").to_sym
|
gsub(/\W+/, "").to_sym
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -217,9 +217,10 @@ class TestCSV::Headers < TestCSV
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_builtin_symbol_converter
|
def test_builtin_symbol_converter
|
||||||
csv = CSV.parse( "One,TWO Three", headers: true,
|
# Note that the trailing space is intentional
|
||||||
return_headers: true,
|
csv = CSV.parse( "One,TWO Three ", headers: true,
|
||||||
header_converters: :symbol )
|
return_headers: true,
|
||||||
|
header_converters: :symbol )
|
||||||
assert_equal([:one, :two_three], csv.headers)
|
assert_equal([:one, :two_three], csv.headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue