1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

re.c: non-regexp name reference

* re.c (rb_reg_regsub): other than regexp has no name references.
  [ruby-core:78686] [Bug #13042]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-12-17 00:52:47 +00:00
parent d4ff516f33
commit 7f4dc81717
2 changed files with 6 additions and 1 deletions

3
re.c
View file

@ -3731,7 +3731,8 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
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);
}

View file

@ -1598,6 +1598,10 @@ CODE
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!