{"action":"created","issue":{"url":"https://api.github.com/repos/ruby/rubyspec/issues/162","labels_url":"https://api.github.com/repos/ruby/rubyspec/issues/162/labels{/name}","comments_url":"https://api.github.com/repos/ruby/rubyspec/issues/162/comments","events_url":"https://api.github.com/repos/ruby/rubyspec/issues/162/events","html_url":"https://github.com/ruby/rubyspec/issues/162","id":117851176,"number":162,"title":"Unsure how to spec out literal hash string key encoding behavior","user":{"login":"headius","id":10135,"avatar_url":"https://avatars.githubusercontent.com/u/10135?v=3","gravatar_id":"","url":"https://api.github.com/users/headius","html_url":"https://github.com/headius","followers_url":"https://api.github.com/users/headius/followers","following_url":"https://api.github.com/users/headius/following{/other_user}","gists_url":"https://api.github.com/users/headius/gists{/gist_id}","starred_url":"https://api.github.com/users/headius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/headius/subscriptions","organizations_url":"https://api.github.com/users/headius/orgs","repos_url":"https://api.github.com/users/headius/repos","events_url":"https://api.github.com/users/headius/events{/privacy}","received_events_url":"https://api.github.com/users/headius/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-11-19T16:28:20Z","updated_at":"2015-11-19T17:09:49Z","closed_at":null,"body":"For jruby/jruby#3405, a bug reporter noted behavioral issues in JRuby's handling of String keys to Hash instances.\r\n\r\nThe correct behaviors are listed below, with JRuby 9.0.4.0 behavior noted where it differs:\r\n\r\n* MRI freezes *and* deduplicates literal String keys in literal Hashes. JRuby 9.0.4.0 deduplicates all String keys inserted into any Hash.\r\n* Frozen string deduplication must not change the encoding of the deduplicated String. JRuby 9.0.4.0 is not checking encodings in the internal deduplication table.\r\n\r\nI'm not sure how to specify these behaviors properly in RubySpec, given that the original test script provided in jruby/jruby#3405 expects the script's default encoding to be ASCII-8BIT and the strings entered into the test Hashes *must* be direct, literal keys. RubySpec files are typically UTF-8, and it would not be appropriate to modify e.g. language/hash_spec.rb to be ASCII-8BIT throughout.\r\n\r\nI *do not* believe we should specify the deduplication effects, since they are not intended to be specified behavior in any Ruby. Any test we write should only be confirming that the various ways to enter String keys into Hash do not lose encoding information.\r\n\r\nI wrote a spec based on the original code, but then realized it did not actually use literal strings in literal hashes where it should, and was not testing what we want to test. I've included it below as an example.\r\n\r\n```ruby\r\n\r\n\r\n  it \"preserves original string keys' encodings after insertion\" do\r\n    ascii_str = 'hello'.force_encoding('ASCII-8BIT')\r\n\r\n    str = ascii_str.dup\r\n    hash1 = {ascii_str.dup => 1}\r\n    hash2 = {str => 2}\r\n\r\n    str.encoding.should == hash1.keys.first.encoding\r\n    str.encoding.should == hash2.keys.first.encoding\r\n\r\n    str = ascii_str.dup.force_encoding('UTF-8')\r\n    hash1 = {'hello'.force_encoding('UTF-8') => 1}\r\n    hash2 = {str => 2}\r\n\r\n    str.encoding.should == hash1.keys.first.encoding\r\n    str.encoding.should == hash2.keys.first.encoding\r\n\r\n    str = ascii_str.dup.force_encoding('UTF-8')\r\n    hash1 = {}\r\n    hash1[str] = 1\r\n    hash2 = {}\r\n    hash2[str] = 2\r\n\r\n    str.encoding.should == hash1.keys.first.encoding\r\n    str.encoding.should == hash2.keys.first.encoding\r\n\r\n    ascii_str2 = 'world'.force_encoding('ASCII-8BIT')\r\n\r\n    str = ascii_str2.dup.force_encoding('UTF-8')\r\n    hash1 = {ascii_str2.dup.force_encoding('UTF-8') => 1}\r\n    hash2 = {str => 2}\r\n\r\n    str.encoding.should == hash1.keys.first.encoding\r\n    str.encoding.should == hash2.keys.first.encoding\r\n\r\n    ascii_str3 = 'unused'.force_encoding('ASCII-8BIT')\r\n    str = ascii_str3.dup\r\n    hash1 = {ascii_str3.dup.force_encoding('UTF-8') => 1}\r\n    hash2 = {str.force_encoding('UTF-8') => 2}\r\n\r\n    str.encoding.should == hash1.keys.first.encoding\r\n    str.encoding.should == hash2.keys.first.encoding\r\n  end\r\n```"},"comment":{"url":"https://api.github.com/repos/ruby/rubyspec/issues/comments/158121760","html_url":"https://github.com/ruby/rubyspec/issues/162#issuecomment-158121760","issue_url":"https://api.github.com/repos/ruby/rubyspec/issues/162","id":158121760,"user":{"login":"headius","id":10135,"avatar_url":"https://avatars.githubusercontent.com/u/10135?v=3","gravatar_id":"","url":"https://api.github.com/users/headius","html_url":"https://github.com/headius","followers_url":"https://api.github.com/users/headius/followers","following_url":"https://api.github.com/users/headius/following{/other_user}","gists_url":"https://api.github.com/users/headius/gists{/gist_id}","starred_url":"https://api.github.com/users/headius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/headius/subscriptions","organizations_url":"https://api.github.com/users/headius/orgs","repos_url":"https://api.github.com/users/headius/repos","events_url":"https://api.github.com/users/headius/events{/privacy}","received_events_url":"https://api.github.com/users/headius/received_events","type":"User","site_admin":false},"created_at":"2015-11-19T17:09:49Z","updated_at":"2015-11-19T17:09:49Z","body":"Yes, I suppose these would be fixtures, like fixtures/hash_with_ascii_keys.rb, fixtures/hash_with_utf8_keys.rb. I'll see if I can come up with something today."}}