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

ruby-changes:3387

From: ko1@a...
Date: 4 Jan 2008 14:02:23 +0900
Subject: [ruby-changes:3387] akr - Ruby:r14880 (trunk): * re.c (rb_reg_prepare_re): check string encoding. Oniguruma doesn't

akr	2008-01-04 14:01:58 +0900 (Fri, 04 Jan 2008)

  New Revision: 14880

  Modified files:
    trunk/ChangeLog
    trunk/re.c
    trunk/test/ruby/test_m17n.rb

  Log:
    * re.c (rb_reg_prepare_re): check string encoding.  Oniguruma doesn't
      support invalid encoding.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14880&r2=14879&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/re.c?r1=14880&r2=14879&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_m17n.rb?r1=14880&r2=14879&diff_format=u

Index: re.c
===================================================================
--- re.c	(revision 14879)
+++ re.c	(revision 14880)
@@ -940,6 +940,12 @@
     int need_recompile = 0;
     rb_encoding *enc;
 
+    if (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN) {
+        rb_raise(rb_eArgError,
+            "broken %s string",
+            rb_enc_name(rb_enc_get(str)));
+    }
+
     rb_reg_check(re);
     /* ignorecase status */
     if (rb_reg_fixed_encoding_p(re)) {
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14879)
+++ ChangeLog	(revision 14880)
@@ -1,3 +1,8 @@
+Fri Jan  4 14:00:50 2008  Tanaka Akira  <akr@f...>
+
+	* re.c (rb_reg_prepare_re): check string encoding.  Oniguruma doesn't
+	  support invalid encoding.
+
 Fri Jan  4 10:22:25 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* re.c (rb_reg_search): avoid inner loop for reverse search.
@@ -54,7 +59,7 @@
 
 Fri Jan  4 00:54:43 2008  Yukihiro Matsumoto  <matz@r...>
 
-	* include/ruby/oniguruma.h: Oniguruma 1.9.1 merged.
+	* include/ruby/oniguruma.h: Oniguruma 5.9.1 merged.
 
 Fri Jan  4 00:20:47 2008  Tanaka Akira  <akr@f...>
 
Index: test/ruby/test_m17n.rb
===================================================================
--- test/ruby/test_m17n.rb	(revision 14879)
+++ test/ruby/test_m17n.rb	(revision 14880)
@@ -877,7 +877,10 @@
         if t != nil
           assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
           assert_equal(s2, t)
-          assert_match(/#{Regexp.escape(s2)}/, s1)
+          assert_match(/#{Regexp.escape(a(s2))}/, a(s1))
+          if s1.valid_encoding?
+            assert_match(/#{Regexp.escape(s2)}/, s1)
+          end
         end
       else
         assert_raise(ArgumentError) { s1[s2] }
@@ -1577,6 +1580,10 @@
         assert_raise(ArgumentError) { s1.scan(s2) }
         next
       end
+      if !s1.valid_encoding?
+        assert_raise(ArgumentError) { s1.scan(s2) }
+        next
+      end
       r = s1.scan(s2)
       r.each {|t|
         assert_equal(s2, t)
@@ -1633,6 +1640,10 @@
         assert_raise(ArgumentError) { s1.split(s2) }
         next
       end
+      if !s1.valid_encoding?
+        assert_raise(ArgumentError) { s1.split(s2) }
+        next
+      end
       t = s1.split(s2)
       t.each {|r|
         assert(a(s1).include?(a(r)))
@@ -1943,6 +1954,10 @@
           lambda { s1.gsub(r2) { s3 } }
         ]
       ].each {|desc, doit|
+        if !s1.valid_encoding?
+          assert_raise(ArgumentError, desc) { doit.call }
+          next
+        end
         if !str_enc_compatible?(s1, s2)
           assert_raise(ArgumentError, desc) { doit.call }
           next
@@ -1993,6 +2008,10 @@
           lambda { t=s1.dup; [t, t.gsub!(r2) { s3 }] }
         ]
       ].each {|desc, doit|
+        if !s1.valid_encoding?
+          assert_raise(ArgumentError, desc) { doit.call }
+          next
+        end
         if !str_enc_compatible?(s1, s2)
           assert_raise(ArgumentError, desc) { doit.call }
           next

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

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