diff options
author | NARUSE, Yui <naruse@airemix.jp> | 2023-03-22 10:34:12 +0900 |
---|---|---|
committer | NARUSE, Yui <naruse@airemix.jp> | 2023-03-22 10:34:12 +0900 |
commit | ad6fe84dfa6935bd6e2c3ef3ee36bed4e8627d0b (patch) | |
tree | b8c2409b52415dd9dfdd00b8d997ff161553b79f | |
parent | 4b4087dce318570f9f9c05e14900325b499fb632 (diff) | |
download | ruby-ad6fe84dfa6935bd6e2c3ef3ee36bed4e8627d0b.tar.gz |
merge revision(s) dddc542e9b61b292d80a96d0d0efbbf58719e3be: [Backport #19476]
[Bug #19476]: correct cache index computation for repetition (#7457)
---
regexec.c | 4 ++--
test/ruby/test_regexp.rb | 5 +++++
2 files changed, 7 insertions(+), 2 deletions(-)
-rw-r--r-- | regexec.c | 4 | ||||
-rw-r--r-- | test/ruby/test_regexp.rb | 5 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 8 insertions, 3 deletions
@@ -1248,10 +1248,10 @@ find_cache_index_table(regex_t* reg, OnigStackType *stk, OnigStackIndex *repeat_ } if (range->upper == 0x7fffffff) { - return range->base_num + range->inner_num * range->lower + (is_inc ? 0 : 1) + item->num; + return range->base_num + range->inner_num * (range->lower - (is_inc ? 1 : 0)) + (is_inc ? 0 : 1) + item->num; } - return range->base_num + range->inner_num * range->lower + (range->inner_num + 1) * (count - range->lower) + item->num; + return range->base_num + range->inner_num * (range->lower - 1) + (range->inner_num + 1) * (count - range->lower + 1) + item->num; } static void diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 01f767dd89..ccdd289dcb 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1792,6 +1792,11 @@ class TestRegexp < Test::Unit::TestCase end; end + def test_bug_19476 # [Bug #19476] + assert_equal("123456789".match(/(?:x?\dx?){2,10}/)[0], "123456789") + assert_equal("123456789".match(/(?:x?\dx?){2,}/)[0], "123456789") + end + def test_linear_time_p assert_send [Regexp, :linear_time?, /a/] assert_send [Regexp, :linear_time?, 'a'] @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 1 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 44 +#define RUBY_PATCHLEVEL 45 #include "ruby/version.h" #include "ruby/internal/abi.h" |