[前][次][番号順一覧][スレッド一覧]

ruby-changes:33295

From: jeg2 <ko1@a...>
Date: Thu, 20 Mar 2014 23:38:27 +0900 (JST)
Subject: [ruby-changes:33295] jeg2:r45374 (trunk): * lib/csv.rb: Fixed a broken regular expression that was causing

jeg2	2014-03-20 23:38:21 +0900 (Thu, 20 Mar 2014)

  New Revision: 45374

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45374

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

  Modified files:
    trunk/ChangeLog
    trunk/lib/csv.rb
    trunk/test/csv/test_features.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45373)
+++ ChangeLog	(revision 45374)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Mar 20 11:37:28 2014  James Edward Gray II  <james@g...>
+
+	* 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@a...>
 
 	* gc.c (objspace_malloc_increase): should not invoke
Index: lib/csv.rb
===================================================================
--- lib/csv.rb	(revision 45373)
+++ lib/csv.rb	(revision 45374)
@@ -1507,8 +1507,7 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L1507
     # 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)
Index: test/csv/test_features.rb
===================================================================
--- test/csv/test_features.rb	(revision 45373)
+++ test/csv/test_features.rb	(revision 45374)
@@ -74,6 +74,14 @@ class TestCSV::Features < TestCSV https://github.com/ruby/ruby/blob/trunk/test/csv/test_features.rb#L74
     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 => "|")

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]