mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user