diff --git a/ChangeLog b/ChangeLog index 320767eca8..2ecf045954 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Thu Mar 20 11:37:28 2014 James Edward Gray II + + * lib/csv.rb: Fixed a broken regular expression that was causing + CSV to miss escaping some special meaning characters when used + in parsing. + Reported by David Unric + [ruby-core:54986] [Bug #8405] + Thu Mar 20 16:53:07 2014 Koichi Sasada * gc.c (objspace_malloc_increase): should not invoke diff --git a/lib/csv.rb b/lib/csv.rb index e5ecf5c9a8..2326792cd7 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1507,8 +1507,7 @@ class CSV # if we can transcode the needed characters # @re_esc = "\\".encode(@encoding) rescue "" - @re_chars = /#{%"[-][\\.^$?*+{}()|# \r\n\t\f\v]".encode(@encoding)}/ - # @re_chars = /#{%"[-][\\.^$?*+{}()|# \r\n\t\f\v]".encode(@encoding, fallback: proc{""})}/ + @re_chars = /#{%"[-\\]\\[\\.^$?*+{}()|# \r\n\t\f\v]".encode(@encoding)}/ init_separators(options) init_parsers(options) diff --git a/test/csv/test_features.rb b/test/csv/test_features.rb index a83fff84d8..ad7e44d854 100755 --- a/test/csv/test_features.rb +++ b/test/csv/test_features.rb @@ -74,6 +74,14 @@ class TestCSV::Features < TestCSV end end + def test_bug_8405 + TEST_CASES.each do |test_case| + assert_equal( test_case.last.map { |t| t.tr('"', "|") unless t.nil? }, + CSV.parse_line( test_case.first.tr('"', "|"), + quote_char: "|" ) ) + end + end + def test_csv_char_readers %w[col_sep row_sep quote_char].each do |reader| csv = CSV.new("abc,def", reader.to_sym => "|")