* 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]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
jeg2 2014-03-20 14:38:21 +00:00
Родитель 3e20c50d50
Коммит 3fb752a921
3 изменённых файлов: 17 добавлений и 2 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Thu Mar 20 11:37:28 2014 James Edward Gray II <james@graysoftinc.com>
* 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 <ko1@atdot.net>
* gc.c (objspace_malloc_increase): should not invoke

Просмотреть файл

@ -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)

Просмотреть файл

@ -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 => "|")