diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-07-01 19:37:43 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-07-01 19:37:43 +0000 |
commit | 3daf4241c882c7a12a4522fefbf1791f0fb5067f (patch) | |
tree | 8b2ee6cc4171c5e8597902c850ce4e0968bc65ae | |
parent | 2211e5d050851d2dcd418c0aacd1026481a7ba68 (diff) | |
download | ruby-3daf4241c882c7a12a4522fefbf1791f0fb5067f.tar.gz |
* 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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | regcomp.c | 7 | ||||
-rw-r--r-- | test/ruby/test_regexp.rb | 1 |
3 files changed, 13 insertions, 4 deletions
@@ -1,3 +1,12 @@ +Sat Jul 2 04:26:14 2016 NARUSE, Yui <naruse@ruby-lang.org> + + * 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@gmail.com> * string.c: Partially reverts r55547 and r55555. @@ -1870,17 +1870,16 @@ noname_disable_map(Node** plink, GroupNumRemap* map, int* counter) (*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; diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 66e2802a23..6cbfdb1a85 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -441,6 +441,7 @@ class TestRegexp < Test::Unit::TestCase 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 |