[ruby-core:115760] [Ruby master Bug#20068] Strings equality doesn't imply hash equality

Issue #20068 has been reported by glebpom (Gleb Pomykalov). ---------------------------------------- Bug #20068: Strings equality doesn't imply hash equality https://bugs.ruby-lang.org/issues/20068 * Author: glebpom (Gleb Pomykalov) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [aarch64-linux] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- 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 => ["", ""] ``` -- https://bugs.ruby-lang.org/
participants (1)
-
glebpom (Gleb Pomykalov)