summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/csv.rb4
-rwxr-xr-xtest/csv/test_headers.rb7
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/csv.rb b/lib/csv.rb
index 30e4b235869..336b42a6974 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -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
}
}
diff --git a/test/csv/test_headers.rb b/test/csv/test_headers.rb
index d8a1c15836f..5ec8932d954 100755
--- a/test/csv/test_headers.rb
+++ b/test/csv/test_headers.rb
@@ -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,