Skip to content

Commit b8ab6af

Browse files
committed
protect NoMethodError from calling to_hash in ==/eql?; close mruby#2002
1 parent 28ab106 commit b8ab6af

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

mrblib/hash.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class Hash
1212
# ISO 15.2.13.4.1
1313
def == (hash)
1414
return true if self.equal?(hash)
15-
hash = hash.to_hash
15+
begin
16+
hash = hash.to_hash
17+
rescue NoMethodError
18+
return false
19+
end
1620
return false if self.size != hash.size
1721
self.each do |k,v|
1822
return false unless hash.key?(k)
@@ -28,7 +32,11 @@ def == (hash)
2832
# ISO 15.2.13.4.32 (x)
2933
def eql?(hash)
3034
return true if self.equal?(hash)
31-
hash = hash.to_hash
35+
begin
36+
hash = hash.to_hash
37+
rescue NoMethodError
38+
return false
39+
end
3240
return false if self.size != hash.size
3341
self.each do |k,v|
3442
return false unless hash.key?(k)

0 commit comments

Comments
 (0)