diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-27 10:55:32 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-27 10:55:32 +0000 |
commit | ea83d7fd0637dd82125ed6ac7cce23c9a0c5653f (patch) | |
tree | 025265b8a6b16b0ac02c43b29b74da98c01e8f2b | |
parent | 745565052a915f8815cd5d3cf299ab4cba20c57c (diff) |
merge revision(s) 57098: [Backport #13042]
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/branches/ruby_2_2@57218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | re.c | 3 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 4 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 12 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Tue Dec 27 19:55:10 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * re.c (rb_reg_regsub): other than regexp has no name references. + [Bug #13042] + Tue Dec 27 19:51:43 2016 Kazuki Yamaguchi <k@rhe.jp> * encoding.c (rb_enc_ascget): handle needmore error from @@ -3468,7 +3468,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(regexp)->src, n) || + if (NIL_P(regexp) || + !rb_enc_compatible(RREGEXP(regexp)->src, n) || (no = name_to_backref_number(regs, regexp, name, name_end)) < 1) { name_to_backref_error(n); } diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 4cd6afdd80..3375a8a3a3 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1507,6 +1507,10 @@ class TestString < Test::Unit::TestCase 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! @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.2.7" #define RUBY_RELEASE_DATE "2016-12-27" -#define RUBY_PATCHLEVEL 408 +#define RUBY_PATCHLEVEL 409 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 12 |