ruby-changes:45025
From: nobu <ko1@a...>
Date: Sat, 17 Dec 2016 09:52:51 +0900 (JST)
Subject: [ruby-changes:45025] nobu:r57098 (trunk): re.c: non-regexp name reference
nobu 2016-12-17 09:52:47 +0900 (Sat, 17 Dec 2016) New Revision: 57098 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57098 Log: re.c: non-regexp name reference * re.c (rb_reg_regsub): other than regexp has no name references. [ruby-core:78686] [Bug #13042] Modified files: trunk/re.c trunk/test/ruby/test_string.rb Index: test/ruby/test_string.rb =================================================================== --- test/ruby/test_string.rb (revision 57097) +++ test/ruby/test_string.rb (revision 57098) @@ -1598,6 +1598,10 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1598 assert_equal(S("Abc"), S("abc").sub("a") {m = $~; "A"}) assert_equal(S("a"), m[0]) assert_equal(/a/, m.regexp) + bug = '[ruby-core:78686] [Bug #13042] other than regexp has no name references' + assert_raise_with_message(IndexError, /oops/, bug) { + 'hello'.gsub('hello', '\k<oops>') + } end def test_sub! Index: re.c =================================================================== --- re.c (revision 57097) +++ re.c (revision 57098) @@ -3731,7 +3731,8 @@ rb_reg_regsub(VALUE str, VALUE src, stru https://github.com/ruby/ruby/blob/trunk/re.c#L3731 if (name_end < e) { VALUE n = rb_str_subseq(str, (long)(name - RSTRING_PTR(str)), (long)(name_end - name)); - if (!rb_enc_compatible(RREGEXP_SRC(regexp), n) || + if (NIL_P(regexp) || + !rb_enc_compatible(RREGEXP_SRC(regexp), n) || (no = name_to_backref_number(regs, regexp, name, name_end)) < 1) { name_to_backref_error(n); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/