1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Return only captured range in MatchData [Bug #18670]

This commit is contained in:
Nobuyoshi Nakada 2022-03-31 18:01:15 +09:00 committed by GitHub
parent ddd83e8462
commit d8189ed23f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2022-03-31 18:01:47 +09:00
Merged: https://github.com/ruby/ruby/pull/5740

Merged-By: nobu <nobu@ruby-lang.org>
2 changed files with 2 additions and 1 deletions

2
re.c
View file

@ -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);

View file

@ -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