ruby-changes:60590
From: usa <ko1@a...>
Date: Tue, 31 Mar 2020 06:49:58 +0900 (JST)
Subject: [ruby-changes:60590] 77d84046c7 (ruby_2_5): merge revision(s) 4f19666e8b144600e959e4673f79d63f98bd637d: [Backport #16508]
https://git.ruby-lang.org/ruby.git/commit/?id=77d84046c7 From 77d84046c728a0a11c83e4b2a18d38e06ff1dc41 Mon Sep 17 00:00:00 2001 From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> Date: Mon, 30 Mar 2020 21:49:42 +0000 Subject: merge revision(s) 4f19666e8b144600e959e4673f79d63f98bd637d: [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_5@67865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e diff --git a/re.c b/re.c index 5030519..fdccea4 100644 --- a/re.c +++ b/re.c @@ -1883,6 +1883,7 @@ match_captures(VALUE match) https://github.com/ruby/ruby/blob/trunk/re.c#L1883 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); } diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index a22975d..fe271dc 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -156,6 +156,10 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L156 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 diff --git a/version.h b/version.h index 76a8079..7fa7786 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1 #define RUBY_VERSION "2.5.8" #define RUBY_RELEASE_DATE "2020-03-31" -#define RUBY_PATCHLEVEL 214 +#define RUBY_PATCHLEVEL 215 #define RUBY_RELEASE_YEAR 2020 #define RUBY_RELEASE_MONTH 3 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/