From 79c89a1750aca76d7aa0cf63c65bcc5b99e65cea Mon Sep 17 00:00:00 2001 From: Herwin Date: Tue, 12 Nov 2024 18:01:43 +0100 Subject: [PATCH] String concatenation uses self's encoding if both are ASCII-only --- spec/core/string/shared/concat.rb | 4 +--- src/string_object.cpp | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/core/string/shared/concat.rb b/spec/core/string/shared/concat.rb index 33f92abf1..dded9a69e 100644 --- a/spec/core/string/shared/concat.rb +++ b/spec/core/string/shared/concat.rb @@ -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 diff --git a/src/string_object.cpp b/src/string_object.cpp index 907c88ed4..876a68615 100644 --- a/src/string_object.cpp +++ b/src/string_object.cpp @@ -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();