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

ruby-changes:73406

From: nagachika <ko1@a...>
Date: Sun, 4 Sep 2022 16:25:24 +0900 (JST)
Subject: [ruby-changes:73406] 6b8bf6ba5d (ruby_3_1): merge revision(s) 6d3f447aecfb56f7d3edbdf9cc68e748e150d7d8: [Backport #18631]

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

From 6b8bf6ba5d1893b3c933c2de3ada1eb59a94b644 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Sun, 4 Sep 2022 16:01:43 +0900
Subject: merge revision(s) 6d3f447aecfb56f7d3edbdf9cc68e748e150d7d8: [Backport
 #18631]

	Fix multiplex backreferencs near end of string in regexp match

	Idea from Jirka Marsik.

	Fixes [Bug #18631]
	---
	 regexec.c                | 6 ++++--
	 test/ruby/test_regexp.rb | 6 ++++++
	 2 files changed, 10 insertions(+), 2 deletions(-)
---
 regexec.c                | 6 ++++--
 test/ruby/test_regexp.rb | 6 ++++++
 version.h                | 2 +-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/regexec.c b/regexec.c
index 8334b16e96..a7b948e99c 100644
--- a/regexec.c
+++ b/regexec.c
@@ -1176,11 +1176,13 @@ static int string_cmp_ic(OnigEncoding enc, int case_fold_flag, https://github.com/ruby/ruby/blob/trunk/regexec.c#L1176
 # define DATA_ENSURE_CHECK1    (s < right_range)
 # define DATA_ENSURE_CHECK(n)  (s + (n) <= right_range)
 # define DATA_ENSURE(n)        if (s + (n) > right_range) goto fail
+# define DATA_ENSURE_CONTINUE(n) if (s + (n) > right_range) continue
 # define ABSENT_END_POS        right_range
 #else
 # define DATA_ENSURE_CHECK1    (s < end)
 # define DATA_ENSURE_CHECK(n)  (s + (n) <= end)
 # define DATA_ENSURE(n)        if (s + (n) > end) goto fail
+# define DATA_ENSURE_CONTINUE(n) if (s + (n) > end) continue
 # define ABSENT_END_POS        end
 #endif /* USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE */
 
@@ -2643,7 +2645,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, https://github.com/ruby/ruby/blob/trunk/regexec.c#L2645
 		  ? STACK_AT(mem_end_stk[mem])->u.mem.pstr
 		  : (UChar* )((void* )mem_end_stk[mem]));
 	  n = pend - pstart;
-	  DATA_ENSURE(n);
+	  DATA_ENSURE_CONTINUE(n);
 	  sprev = s;
 	  swork = s;
 	  STRING_CMP_VALUE(pstart, swork, n, is_fail);
@@ -2682,7 +2684,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, https://github.com/ruby/ruby/blob/trunk/regexec.c#L2684
 		  ? STACK_AT(mem_end_stk[mem])->u.mem.pstr
 		  : (UChar* )((void* )mem_end_stk[mem]));
 	  n = pend - pstart;
-	  DATA_ENSURE(n);
+	  DATA_ENSURE_CONTINUE(n);
 	  sprev = s;
 	  swork = s;
 	  STRING_CMP_VALUE_IC(case_fold_flag, pstart, &swork, n, end, is_fail);
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index c183988303..16a6ed921f 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -1406,6 +1406,12 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L1406
     end;
   end
 
+  def test_bug18631
+    assert_kind_of MatchData, /(?<x>a)(?<x>aa)\k<x>/.match("aaaaa")
+    assert_kind_of MatchData, /(?<x>a)(?<x>aa)\k<x>/.match("aaaa")
+    assert_kind_of MatchData, /(?<x>a)(?<x>aa)\k<x>/.match("aaaab")
+  end
+
   # This assertion is for porting x2() tests in testpy.py of Onigmo.
   def assert_match_at(re, str, positions, msg = nil)
     re = Regexp.new(re) unless re.is_a?(Regexp)
diff --git a/version.h b/version.h
index 27440ec8ee..f7dbdf5382 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L11
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
 #define RUBY_VERSION_TEENY 3
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 45
+#define RUBY_PATCHLEVEL 46
 
 #define RUBY_RELEASE_YEAR 2022
 #define RUBY_RELEASE_MONTH 9
-- 
cgit v1.2.1


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

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