diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-03-31 18:01:15 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-31 18:01:15 +0900 |
commit | d8189ed23f02dd197453279aeee9be1785337d4f (patch) | |
tree | f9f23ce77a5f5695fbde1abe75da846acb64b671 | |
parent | ddd83e8462db32b7403470ef92ed73ee0daef02b (diff) |
Return only captured range in `MatchData` [Bug #18670]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5740
Merged-By: nobu <nobu@ruby-lang.org>
-rw-r--r-- | re.c | 2 | ||||
-rw-r--r-- | test/ruby/test_regexp.rb | 1 |
2 files changed, 2 insertions, 1 deletions
@@ -2159,7 +2159,7 @@ match_aref(int argc, VALUE *argv, VALUE match) else if (beg > num_regs) { return Qnil; } - else if (beg+len > num_regs) { + if (beg+len > num_regs) { len = num_regs - beg; } return match_ary_subseq(match, beg, len, Qnil); diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 7f787f99f5..4e840f23ad 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -488,6 +488,7 @@ class TestRegexp < Test::Unit::TestCase assert_nil(m[5]) assert_raise(IndexError) { m[:foo] } assert_raise(TypeError) { m[nil] } + assert_equal(["baz", nil], m[-2, 3]) end def test_match_values_at |