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

merge revision(s) 4f19666e8b: [Backport #16508]

`Regexp` in `MatchData` can be `nil`

	`String#sub` with a string pattern defers creating a `Regexp`
	until `MatchData#regexp` creates a `Regexp` from the matched
	string.  `Regexp#last_match(group_name)` accessed its content
	without creating the `Regexp` though.  [Bug #16508]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagachika 2020-03-07 09:38:30 +00:00
parent 12c7321d75
commit ca74f62a3a
3 changed files with 8 additions and 3 deletions

1
re.c
View file

@ -1936,6 +1936,7 @@ match_captures(VALUE match)
static int
name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end)
{
if (NIL_P(regexp)) return -1;
return onig_name_to_backref_number(RREGEXP_PTR(regexp),
(const unsigned char *)name, (const unsigned char *)name_end, regs);
}

View file

@ -161,6 +161,10 @@ class TestRegexp < Test::Unit::TestCase
s = "foo"
s[/(?<bar>o)/, "bar"] = "baz"
assert_equal("fbazo", s)
/.*/ =~ "abc"
"a".sub("a", "")
assert_raise(IndexError) {Regexp.last_match(:_id)}
end
def test_named_capture_with_nul

View file

@ -1,10 +1,10 @@
#define RUBY_VERSION "2.6.6"
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 125
#define RUBY_PATCHLEVEL 126
#define RUBY_RELEASE_YEAR 2020
#define RUBY_RELEASE_MONTH 2
#define RUBY_RELEASE_DAY 15
#define RUBY_RELEASE_MONTH 3
#define RUBY_RELEASE_DAY 7
#include "ruby/version.h"