Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String concatenation uses self's encoding if both are ASCII-only #2328

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions spec/core/string/shared/concat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@

describe "when self and the argument are in different ASCII-compatible encodings" do
it "uses self's encoding if both are ASCII-only" do
NATFIXME "it uses self's encoding if both are ASCII-only", exception: SpecFailedException do
"abc".encode("UTF-8").send(@method, "123".encode("SHIFT_JIS")).encoding.should == Encoding::UTF_8
end
"abc".encode("UTF-8").send(@method, "123".encode("SHIFT_JIS")).encoding.should == Encoding::UTF_8
end

it "uses self's encoding if the argument is ASCII-only" do
Expand Down
2 changes: 1 addition & 1 deletion src/string_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3481,7 +3481,7 @@ EncodingObject *StringObject::negotiate_compatible_encoding(const StringObject *
if (m_encoding->num() == Encoding::ASCII_8BIT)
return m_encoding.ptr();

if (this_is_ascii)
else if (this_is_ascii && !other_is_ascii)
return other_string->m_encoding.ptr();
else
return m_encoding.ptr();
Expand Down
Loading