зеркало из https://github.com/github/ruby.git
Fix issue with Array#rindex when rb_equal modifies receiver array
Fixes [Bug #15951] Closes: https://github.com/ruby/ruby/pull/2250
This commit is contained in:
Родитель
fd9ac1e76b
Коммит
c033dc3073
3
array.c
3
array.c
|
@ -1805,6 +1805,9 @@ rb_ary_rindex(int argc, VALUE *argv, VALUE ary)
|
|||
if (rb_equal(e, val)) {
|
||||
return LONG2NUM(i);
|
||||
}
|
||||
if (i > RARRAY_LEN(ary)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
|
|
@ -1438,6 +1438,16 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_nil(a.rindex([1,2]))
|
||||
|
||||
assert_equal(3, a.rindex(99) {|x| x == [1,2,3] })
|
||||
|
||||
bug15951 = "[Bug #15951]"
|
||||
o2 = Object.new
|
||||
def o2.==(other)
|
||||
other.replace([]) if Array === other
|
||||
false
|
||||
end
|
||||
a = Array.new(10)
|
||||
a.fill(o2)
|
||||
assert_nil(a.rindex(a), bug15951)
|
||||
end
|
||||
|
||||
def test_shift
|
||||
|
|
Загрузка…
Ссылка в новой задаче