Actions
Bug #20068
closedStrings equality doesn't imply hash equality
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [aarch64-linux]
Description
It is well-known that the equality of two objects should lead to the equality of their' hashes (https://ruby-doc.org/3.2.2/Object.html#method-i-hash)
Empty strings, where one encoding is not ASCII-compatible (UTF-16 in the following example), and another is ASCII-compatible don't follow this rule:
irb(main):038:0> l = ""
=> ""
irb(main):039:0> r = l.encode('UTF-16LE')
=> ""
irb(main):040:0> l.hash
=> 1212370190964414646
irb(main):041:0> r.hash
=> 1212370190964414642
irb(main):042:0> l.hash == r.hash
=> false
irb(main):043:0> l.eql?(r)
=> true
irb(main):044:0> l
=> ""
irb(main):045:0> r
=> ""
irb(main):046:0> [l,r].uniq
=> ["", ""]
Actions
Like0
Like0