diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-16 11:58:41 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-16 11:58:41 +0000 |
commit | e62309856b193b7f3e5208dc0f0510d02365d7fc (patch) | |
tree | a21a02009d5ed2b73192b8279701f6ad8bf180a2 | |
parent | 6fa7bf5e7b2a6ee8b60c874b7abe60981d395264 (diff) |
merge revision(s) 55562: [Backport #12454]
* 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/branches/ruby_2_2@55939 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 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 14 insertions, 5 deletions
@@ -1,3 +1,12 @@ +Tue Aug 16 20:58:11 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] + Tue Aug 16 20:56:30 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> * missing/crypt.c: fix size macros to use configured values @@ -1876,17 +1876,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 321a1989c2..144986dd56 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -390,6 +390,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 @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.2.6" #define RUBY_RELEASE_DATE "2016-08-16" -#define RUBY_PATCHLEVEL 365 +#define RUBY_PATCHLEVEL 366 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 8 |