Add specs for rb_interned_str and rb_interned_str_cstr#1327
Merged
eregon merged 6 commits intoruby:masterfrom Jan 18, 2026
Merged
Add specs for rb_interned_str and rb_interned_str_cstr#1327eregon merged 6 commits intoruby:masterfrom
eregon merged 6 commits intoruby:masterfrom
Conversation
Member
Author
|
Upstream: https://bugs.ruby-lang.org/issues/21842 |
Updated them to the current status of the upstream bug report, which is all strings are binary. This might change to either ASCII-7BIT or BINARY. The current specs pass with the latest upstream version of Ruby 4.1 (commit 3e13b7d4ef)
Member
Author
|
Updated the specs to match the behaviour of ruby/ruby#15888. This might not be the final version, ruby/ruby#15894 has a proposed change to return US-ASCII if everything is ASCII compatible, and BINARY otherwise. |
Member
Author
|
Updated again to match the new behaviour of ruby/ruby#15894 |
It the whole string is valid ASCII, it returns US-ASCII encoding. Otherwise, it is BINARY. The current specs pass with the latest upstream version of Ruby 4.1 (commit 78b7646bdb)
0912e58 to
f737668
Compare
eregon
reviewed
Jan 17, 2026
optional/capi/string_spec.rb
Outdated
| end | ||
| end | ||
|
|
||
| it "returns the same frozen strings for different encodings" do |
Member
There was a problem hiding this comment.
This description/test is confusing because the encoding is ignored by that function, it only receives char* and length.
eregon
reviewed
Jan 17, 2026
optional/capi/string_spec.rb
Outdated
| end | ||
| end | ||
|
|
||
| it "returns the same frozen strings for different encodings" do |
Add full checks for the behaviour around US_ASCII/BINARY encoding choice. Remove some of the checks that depend on the encoding of the source string, since this function uses C char* without any encoding information.
The documentation in the MRI source refers to rb_interned_str as being similar, this test is just to accentuate the difference between these two funcitons.
Member
Author
|
I've removed both tests for encoded strings, and added two additional tests:
|
eregon
reviewed
Jan 18, 2026
eregon
approved these changes
Jan 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Keeping this as a draft for now. The comment in the MRI source for
rb_interned_strreads as follows:But the encoding of the result is always
Encoding::US_ASCII, which leads to the following spec:I will create an issue for Ruby to get clarification about the desired behaviour.