Skip to content

Commit cd716a6

Browse files
committed
Fix String#-@ for strings that cannot be deduplicated.
1 parent c9cb008 commit cd716a6

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

spec/ruby/core/string/uminus_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,23 @@
4141

4242
(-dynamic).should_not equal("this string is frozen".freeze)
4343
(-dynamic).should_not equal(-"this string is frozen".freeze)
44+
(-dynamic).should == "this string is frozen"
4445
end
4546

4647
it "does not deduplicate tainted strings" do
4748
dynamic = %w(this string is frozen).join(' ')
4849
dynamic.taint
4950
(-dynamic).should_not equal("this string is frozen".freeze)
5051
(-dynamic).should_not equal(-"this string is frozen".freeze)
52+
(-dynamic).should == "this string is frozen"
5153
end
5254

5355
it "does not deduplicate strings with additional instance variables" do
5456
dynamic = %w(this string is frozen).join(' ')
5557
dynamic.instance_variable_set(:@foo, :bar)
5658
(-dynamic).should_not equal("this string is frozen".freeze)
5759
(-dynamic).should_not equal(-"this string is frozen".freeze)
60+
(-dynamic).should == "this string is frozen"
5861
end
5962
end
6063

src/main/ruby/core/string.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,8 @@ def -@
15941594
unless str.tainted? || !(str.instance_variables).empty?
15951595
Truffle::Ropes.flatten_rope(str)
15961596
Truffle.invoke_primitive(:string_intern, str)
1597+
else
1598+
str
15971599
end
15981600
end
15991601

0 commit comments

Comments
 (0)