[ruby-core:113953] [Ruby master Bug#19739] Key cannot be found in a Hash when slice! method is applied to the key

Issue #19739 has been reported by ilya.andreyuk (Ilya Andreyuk). ---------------------------------------- Bug #19739: Key cannot be found in a Hash when slice! method is applied to the key https://bugs.ruby-lang.org/issues/19739 * Author: ilya.andreyuk (Ilya Andreyuk) * Status: Open * Priority: Normal * ruby -v: 3.1.4 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Hello, Key cannot be found in a Hash when slice! method is applied to the key. I cannot reproduce this behaviour with sub! or gsub! methods: ``` ruby hash = {} key = "ABC OÜ" key.slice!(/ oü$/i) # key.sub!(/ oü$/i, '') # key.gsub!(/ oü$/i, '') hash[key] = true "#{key} in #{hash}: value is #{hash[key]}" => "ABC in {\"ABC\"=>true}: value is " ``` Also it seems that ruby 2.7.6 and 3.2.2 don't have this issue. -- https://bugs.ruby-lang.org/

Issue #19739 has been updated by byroot (Jean Boussier). That is very interesting. The two strings are identical (aside from one being frozen): ```ruby require "objspace" hash = {} key = "ABC OÜ" p key.hash key.slice!(/ oü$/i) p key.hash puts ObjectSpace.dump(key) hash[key] = true p "#{key} in #{hash}: value is #{hash[key].inspect}" puts ObjectSpace.dump(hash.keys.first) p [hash.keys.first, key, hash.keys.first == key] p [hash.keys.first.hash, key.hash] ``` ``` 1883393806954673666 -2878200511277543492 {"address":"0x10129f048", "type":"STRING", "class":"0x1011c2418", "embedded":true, "bytesize":3, "encoding":"UTF-8", "memsize":40, "flags":{"wb_protected":true}} "ABC in {\"ABC\"=>true}: value is nil" {"address":"0x10129ebc0", "type":"STRING", "class":"0x1011c2418", "frozen":true, "embedded":true, "fstring":true, "bytesize":3, "value":"ABC", "encoding":"UTF-8", "memsize":40, "flags":{"wb_protected":true}} ["ABC", "ABC", true] [-2878200511277543491, -2878200511277543491] ``` The hash code is the same, and `==` returns true. I had a quick look at recent changes in `String#slice!` that could explain why it's fixed in 3.2, but didn't spot anything yet. What is interesting though is that the first access to `key.hash` returns `-2878200511277543492`, but then later it consistently returns `-2878200511277543491`. I wonder if there is an off by one bug somewhere. ---------------------------------------- Bug #19739: Key cannot be found in a Hash when slice! method is applied to the key https://bugs.ruby-lang.org/issues/19739#change-103610 * Author: ilya.andreyuk (Ilya Andreyuk) * Status: Open * Priority: Normal * ruby -v: 3.1.4 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Hello, Key cannot be found in a Hash when slice! method is applied to the key. I cannot reproduce this behaviour with sub! or gsub! methods: ``` ruby hash = {} key = "ABC OÜ" key.slice!(/ oü$/i) # key.sub!(/ oü$/i, '') # key.gsub!(/ oü$/i, '') hash[key] = true "#{key} in #{hash}: value is #{hash[key]}" => "ABC in {\"ABC\"=>true}: value is " ``` Also it seems that ruby 2.7.6 and 3.2.2 don't have this issue. -- https://bugs.ruby-lang.org/

Issue #19739 has been updated by byroot (Jean Boussier). Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN to 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: DONTNEED I suspect https://github.com/ruby/ruby/pull/5867 is what fixed it, but don't have time to confirm just yet. ---------------------------------------- Bug #19739: Key cannot be found in a Hash when slice! method is applied to the key https://bugs.ruby-lang.org/issues/19739#change-103611 * Author: ilya.andreyuk (Ilya Andreyuk) * Status: Open * Priority: Normal * ruby -v: 3.1.4 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: DONTNEED ---------------------------------------- Hello, Key cannot be found in a Hash when slice! method is applied to the key. I cannot reproduce this behaviour with sub! or gsub! methods: ``` ruby hash = {} key = "ABC OÜ" key.slice!(/ oü$/i) # key.sub!(/ oü$/i, '') # key.gsub!(/ oü$/i, '') hash[key] = true "#{key} in #{hash}: value is #{hash[key]}" => "ABC in {\"ABC\"=>true}: value is " ``` Also it seems that ruby 2.7.6 and 3.2.2 don't have this issue. -- https://bugs.ruby-lang.org/

Issue #19739 has been updated by byroot (Jean Boussier). Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: DONTNEED to 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONTNEED Ok, so after bisecting it appears that what fixed it was: https://github.com/ruby/ruby/commit/b0b9f7201acab05c2a3ad92c3043a1f01df3e17f This won't be easy to backport though, as it was a performance patch. Especially since it had to be fixed later with https://github.com/ruby/ruby/pull/7437/commits/2d0c804e5640475202b7c24559bbe... We might need to craft a patch specifically to fix that bug. ---------------------------------------- Bug #19739: Key cannot be found in a Hash when slice! method is applied to the key https://bugs.ruby-lang.org/issues/19739#change-103615 * Author: ilya.andreyuk (Ilya Andreyuk) * Status: Open * Priority: Normal * ruby -v: 3.1.4 * Backport: 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONTNEED ---------------------------------------- Hello, Key cannot be found in a Hash when slice! method is applied to the key. I cannot reproduce this behaviour with sub! or gsub! methods: ``` ruby hash = {} key = "ABC OÜ" key.slice!(/ oü$/i) # key.sub!(/ oü$/i, '') # key.gsub!(/ oü$/i, '') hash[key] = true "#{key} in #{hash}: value is #{hash[key]}" => "ABC in {\"ABC\"=>true}: value is " ``` Also it seems that ruby 2.7.6 and 3.2.2 don't have this issue. -- https://bugs.ruby-lang.org/

Issue #19739 has been updated by byroot (Jean Boussier). OK fix is here: https://github.com/ruby/ruby/pull/7965 ---------------------------------------- Bug #19739: Key cannot be found in a Hash when slice! method is applied to the key https://bugs.ruby-lang.org/issues/19739#change-103616 * Author: ilya.andreyuk (Ilya Andreyuk) * Status: Open * Priority: Normal * ruby -v: 3.1.4 * Backport: 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONTNEED ---------------------------------------- Hello, Key cannot be found in a Hash when slice! method is applied to the key. I cannot reproduce this behaviour with sub! or gsub! methods: ``` ruby hash = {} key = "ABC OÜ" key.slice!(/ oü$/i) # key.sub!(/ oü$/i, '') # key.gsub!(/ oü$/i, '') hash[key] = true "#{key} in #{hash}: value is #{hash[key]}" => "ABC in {\"ABC\"=>true}: value is " ``` Also it seems that ruby 2.7.6 and 3.2.2 don't have this issue. -- https://bugs.ruby-lang.org/

Issue #19739 has been updated by byroot (Jean Boussier). cc @nagachika is a PR targeting `ruby_3_1` OK? Or should I submit the patch differently? ---------------------------------------- Bug #19739: Key cannot be found in a Hash when slice! method is applied to the key https://bugs.ruby-lang.org/issues/19739#change-103617 * Author: ilya.andreyuk (Ilya Andreyuk) * Status: Open * Priority: Normal * ruby -v: 3.1.4 * Backport: 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONTNEED ---------------------------------------- Hello, Key cannot be found in a Hash when slice! method is applied to the key. I cannot reproduce this behaviour with sub! or gsub! methods: ``` ruby hash = {} key = "ABC OÜ" key.slice!(/ oü$/i) # key.sub!(/ oü$/i, '') # key.gsub!(/ oü$/i, '') hash[key] = true "#{key} in #{hash}: value is #{hash[key]}" => "ABC in {\"ABC\"=>true}: value is " ``` Also it seems that ruby 2.7.6 and 3.2.2 don't have this issue. -- https://bugs.ruby-lang.org/

Issue #19739 has been updated by hsbt (Hiroshi SHIBATA). @byroot `ruby_3_1` is handled by @usa now. ---------------------------------------- Bug #19739: String coderange not cleared by String#slice! https://bugs.ruby-lang.org/issues/19739#change-103619 * Author: ilya.andreyuk (Ilya Andreyuk) * Status: Open * Priority: Normal * ruby -v: 3.1.4 * Backport: 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONTNEED ---------------------------------------- Hello, Key cannot be found in a Hash when slice! method is applied to the key. I cannot reproduce this behaviour with sub! or gsub! methods: ``` ruby hash = {} key = "ABC OÜ" key.slice!(/ oü$/i) # key.sub!(/ oü$/i, '') # key.gsub!(/ oü$/i, '') hash[key] = true "#{key} in #{hash}: value is #{hash[key]}" => "ABC in {\"ABC\"=>true}: value is " ``` Also it seems that ruby 2.7.6 and 3.2.2 don't have this issue. -- https://bugs.ruby-lang.org/

Issue #19739 has been updated by byroot (Jean Boussier). The commit to backport would be: https://github.com/Shopify/ruby/commit/3b351ee62d4206bb72301c2e98dcb173f1e35... ---------------------------------------- Bug #19739: String coderange not cleared by String#slice! https://bugs.ruby-lang.org/issues/19739#change-103621 * Author: ilya.andreyuk (Ilya Andreyuk) * Status: Closed * Priority: Normal * ruby -v: 3.1.4 * Backport: 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONTNEED ---------------------------------------- Hello, Key cannot be found in a Hash when slice! method is applied to the key. I cannot reproduce this behaviour with sub! or gsub! methods: ``` ruby hash = {} key = "ABC OÜ" key.slice!(/ oü$/i) # key.sub!(/ oü$/i, '') # key.gsub!(/ oü$/i, '') hash[key] = true "#{key} in #{hash}: value is #{hash[key]}" => "ABC in {\"ABC\"=>true}: value is " ``` Also it seems that ruby 2.7.6 and 3.2.2 don't have this issue. -- https://bugs.ruby-lang.org/

Issue #19739 has been updated by usa (Usaku NAKAMURA). Backport changed from 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONTNEED to 3.0: REQUIRED, 3.1: DONE, 3.2: DONTNEED ruby_3_1 7e926c4d8c2e785d174161b38a8a688b19ea4b99. ---------------------------------------- Bug #19739: String coderange not cleared by String#slice! https://bugs.ruby-lang.org/issues/19739#change-103978 * Author: ilya.andreyuk (Ilya Andreyuk) * Status: Closed * Priority: Normal * ruby -v: 3.1.4 * Backport: 3.0: REQUIRED, 3.1: DONE, 3.2: DONTNEED ---------------------------------------- Hello, Key cannot be found in a Hash when slice! method is applied to the key. I cannot reproduce this behaviour with sub! or gsub! methods: ``` ruby hash = {} key = "ABC OÜ" key.slice!(/ oü$/i) # key.sub!(/ oü$/i, '') # key.gsub!(/ oü$/i, '') hash[key] = true "#{key} in #{hash}: value is #{hash[key]}" => "ABC in {\"ABC\"=>true}: value is " ``` Also it seems that ruby 2.7.6 and 3.2.2 don't have this issue. -- https://bugs.ruby-lang.org/
participants (4)
-
byroot (Jean Boussier)
-
hsbt (Hiroshi SHIBATA)
-
ilya.andreyuk (Ilya Andreyuk)
-
usa (Usaku NAKAMURA)