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

ruby-changes:43489

From: naruse <ko1@a...>
Date: Sat, 2 Jul 2016 04:37:48 +0900 (JST)
Subject: [ruby-changes:43489] naruse:r55562 (trunk): * regcomp.c (noname_disable_map): don't optimize out group 0

naruse	2016-07-02 04:37:43 +0900 (Sat, 02 Jul 2016)

  New Revision: 55562

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55562

  Log:
    * regcomp.c (noname_disable_map): don't optimize out group 0
      Ruby's Regexp doesn't allow normal numbered groups if the regexp
      has named groups. On such case it optimizes out related NT_ENCLOSE.
      But even on the case it can use \g<0>.
      This fix not to remove NT_ENCLOSE whose regnum is 0.
      [ruby-core:75828] [Bug #12454]

  Modified files:
    trunk/ChangeLog
    trunk/regcomp.c
    trunk/test/ruby/test_regexp.rb
Index: test/ruby/test_regexp.rb
===================================================================
--- test/ruby/test_regexp.rb	(revision 55561)
+++ test/ruby/test_regexp.rb	(revision 55562)
@@ -441,6 +441,7 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L441
     assert_raise(RegexpError) { Regexp.new(")(") }
     assert_raise(RegexpError) { Regexp.new('[\\40000000000') }
     assert_raise(RegexpError) { Regexp.new('[\\600000000000.') }
+    assert_raise(RegexpError) { Regexp.new("((?<v>))\\g<0>") }
   end
 
   def test_unescape
Index: regcomp.c
===================================================================
--- regcomp.c	(revision 55561)
+++ regcomp.c	(revision 55562)
@@ -1870,17 +1870,16 @@ noname_disable_map(Node** plink, GroupNu https://github.com/ruby/ruby/blob/trunk/regcomp.c#L1870
 	  (*counter)++;
 	  map[en->regnum].new_val = *counter;
 	  en->regnum = *counter;
-	  r = noname_disable_map(&(en->target), map, counter);
 	}
-	else {
+	else if (en->regnum != 0) {
 	  *plink = en->target;
 	  en->target = NULL_NODE;
 	  onig_node_free(node);
 	  r = noname_disable_map(plink, map, counter);
+	  break;
 	}
       }
-      else
-	r = noname_disable_map(&(en->target), map, counter);
+      r = noname_disable_map(&(en->target), map, counter);
     }
     break;
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55561)
+++ ChangeLog	(revision 55562)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jul  2 04:26:14 2016  NARUSE, Yui  <naruse@r...>
+
+	* regcomp.c (noname_disable_map): don't optimize out group 0
+	  Ruby's Regexp doesn't allow normal numbered groups if the regexp
+	  has named groups. On such case it optimizes out related NT_ENCLOSE.
+	  But even on the case it can use \g<0>.
+	  This fix not to remove NT_ENCLOSE whose regnum is 0.
+	  [ruby-core:75828] [Bug #12454]
+
 Sat Jul  2 03:09:27 2016  Naohisa Goto  <ngotogenome@g...>
 
 	* string.c: Partially reverts r55547 and r55555.

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

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