From db30b0636f0aee266dfbb3030463baf9603e06b4 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 10 May 2024 20:31:26 +0900 Subject: [PATCH] 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. --- mrbgems/mruby-array-ext/mrblib/array.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mrbgems/mruby-array-ext/mrblib/array.rb b/mrbgems/mruby-array-ext/mrblib/array.rb index 1339fc19b..5add0a5bd 100644 --- a/mrbgems/mruby-array-ext/mrblib/array.rb +++ b/mrbgems/mruby-array-ext/mrblib/array.rb @@ -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