diff options
author | TSUYUSATO Kitsune <make.just.on@gmail.com> | 2023-03-13 18:31:13 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-13 18:31:13 +0900 |
commit | dddc542e9b61b292d80a96d0d0efbbf58719e3be (patch) | |
tree | 667dd3206c3a66e05d9cc0cb3a9e954ee1ddacc1 | |
parent | 1e73bdbfc49b47ab5f45506f2a2a70660ee0e6e2 (diff) | |
download | ruby-dddc542e9b61b292d80a96d0d0efbbf58719e3be.tar.gz |
[Bug #19476]: correct cache index computation for repetition (#7457)
-rw-r--r-- | regexec.c | 4 | ||||
-rw-r--r-- | test/ruby/test_regexp.rb | 5 |
2 files changed, 7 insertions, 2 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 f3b9f68ffd..a2997af106 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1765,6 +1765,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'] |