mruby-array-ext: use NONE.equal?() for NONE comparison; fix #6262

The equal (`==`) method of the comparison target might be redefined
(the root cause of #6262), and not supposed to be compared with NONE.
To reduce chance for the problem, we use `NONE.equal?()` for comparison.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-05-10 20:31:26 +09:00
parent 058a4ab5c6
commit db30b0636f
+2 -2
View File
@@ -339,7 +339,7 @@ class Array
end
if idx < 0 || size <= idx
return block.call(n) if block
if ifnone == NONE
if NONE.equal?(ifnone)
raise IndexError, "index #{n} outside of array bounds: #{-size}...#{size}"
end
return ifnone
@@ -714,7 +714,7 @@ class Array
#
# ISO 15.2.12.5.14
def index(val=NONE, &block)
return to_enum(:find_index, val) if !block && val == NONE
return to_enum(:find_index, val) if !block && NONE.equal?(val)
if block
idx = 0