[前][次][番号順一覧][スレッド一覧]

ruby-changes:60321

From: nagachika <ko1@a...>
Date: Sat, 7 Mar 2020 18:38:42 +0900 (JST)
Subject: [ruby-changes:60321] ca74f62a3a (ruby_2_6): merge revision(s) 4f19666e8b144600e959e4673f79d63f98bd637d: [Backport #16508]

https://git.ruby-lang.org/ruby.git/commit/?id=ca74f62a3a

From ca74f62a3abfa13c353737c74624d3ef00777036 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Sat, 7 Mar 2020 09:38:30 +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_6@67838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

diff --git a/re.c b/re.c
index 105c02a..a866630 100644
--- a/re.c
+++ b/re.c
@@ -1936,6 +1936,7 @@ match_captures(VALUE match) https://github.com/ruby/ruby/blob/trunk/re.c#L1936
 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 aafad0b..38147c7 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -161,6 +161,10 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L161
     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 2b2fd53..314a76a 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1
 #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"
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]