[#115884] Windows Ruby 3.2.2: Non-English character added to Windows Registry String Value — Jay Mav via ruby-core <ruby-core@...>
Hello,
3 messages
2023/12/24
[ruby-core:115760] [Ruby master Bug#20068] Strings equality doesn't imply hash equality
From:
"glebpom (Gleb Pomykalov) via ruby-core" <ruby-core@...>
Date:
2023-12-16 02:12:44 UTC
List:
ruby-core #115760
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/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/