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

ruby-changes:2584

From: ko1@a...
Date: 2 Dec 2007 09:16:47 +0900
Subject: [ruby-changes:2584] akr - Ruby:r14075 (trunk): * parse.y (regexp): fix /#{}\xa1\xa2/e to be EUC-JP.

akr	2007-12-02 09:16:24 +0900 (Sun, 02 Dec 2007)

  New Revision: 14075

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_m17n.rb

  Log:
    * parse.y (regexp): fix /#{}\xa1\xa2/e to be EUC-JP. 
      (reg_fragment_setenc_gen): extracted from reg_compile_gen.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/parse.y?r1=14075&r2=14074
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14075&r2=14074
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_m17n.rb?r1=14075&r2=14074

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14074)
+++ ChangeLog	(revision 14075)
@@ -1,3 +1,8 @@
+Sun Dec  2 09:12:48 2007  Tanaka Akira  <akr@f...>
+
+	* parse.y (regexp): fix /#{}\xa1\xa2/e to be EUC-JP. 
+	  (reg_fragment_setenc_gen): extracted from reg_compile_gen.
+
 Sun Dec  2 01:39:51 2007  Tanaka Akira  <akr@f...>
 
 	* include/ruby/intern.h (rb_uv_to_utf8): declared.
Index: parse.y
===================================================================
--- parse.y	(revision 14074)
+++ parse.y	(revision 14075)
@@ -442,6 +442,8 @@
 
 static VALUE reg_compile_gen(struct parser_params*, VALUE, int);
 #define reg_compile(str,options) reg_compile_gen(parser, str, options)
+static void reg_fragment_setenc_gen(struct parser_params*, VALUE, int);
+#define reg_fragment_setenc(str,options) reg_fragment_setenc_gen(parser, str, options)
 #else
 #define remove_begin(node) (node)
 #endif /* !RIPPER */
@@ -3642,6 +3644,7 @@
 		    /*%%%*/
 			int options = $3;
 			NODE *node = $2;
+                        NODE *list;
 			if (!node) {
 			    node = NEW_LIT(reg_compile(STR_NEW0(), options));
 			}
@@ -3663,6 +3666,12 @@
 				nd_set_type(node, NODE_DREGX);
 			    }
 			    node->nd_cflag = options & RE_OPTION_MASK;
+                            reg_fragment_setenc(node->nd_lit, options);
+                            for (list = node->nd_next; list; list = list->nd_next) {
+                                if (nd_type(list->nd_head) == NODE_STR) {
+                                    reg_fragment_setenc(list->nd_head->nd_lit, options);
+                                }
+                            }
 			    break;
 			}
 			$$ = node;
@@ -8436,10 +8445,9 @@
 
 VALUE rb_reg_compile(VALUE str, int options);
 
-static VALUE
-reg_compile_gen(struct parser_params* parser, VALUE str, int options)
+static void
+reg_fragment_setenc_gen(struct parser_params* parser, VALUE str, int options)
 {
-    VALUE re;
     int c = RE_OPTION_ENCODING_IDX(options);
 
     if (c) {
@@ -8453,6 +8461,14 @@
 	}
 	ENCODING_SET(str, idx);
     }
+}
+
+static VALUE
+reg_compile_gen(struct parser_params* parser, VALUE str, int options)
+{
+    VALUE re;
+
+    reg_fragment_setenc(str, options);
     re = rb_reg_compile(str, options & RE_OPTION_MASK);
     if (NIL_P(re)) {
 	RB_GC_GUARD(re) = rb_obj_as_string(rb_errinfo());
Index: test/ruby/test_m17n.rb
===================================================================
--- test/ruby/test_m17n.rb	(revision 14074)
+++ test/ruby/test_m17n.rb	(revision 14075)
@@ -301,4 +301,12 @@
       }
     }
   end
+
+  def test_dynamic_euc_regexp
+    assert_encoding("EUC-JP", /#{}\xc0\xa1/e.encoding)
+    assert_raise(RegexpError) { eval('/\xa1#{}/e') }
+    assert_raise(RegexpError) { eval('/#{}\xa1/e') }
+    #assert_raise(SyntaxError) { eval('/\xa1#{}\xa1/e') }
+    #assert_raise(SyntaxError) { s = e('\xa1'); /#{s}#{s}/ }
+  end
 end

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

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