Skip to content

Commit aec8c03

Browse files
committed
[GR-15285] String intern bug fix.
PullRequest: truffleruby/843
2 parents 2dbf281 + 6fb02e0 commit aec8c03

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Bug fixes:
1212

1313
Compatibility
1414

15-
* `String#-@` now performs string deduplication
15+
* `String#-@` now performs string deduplication (#1608).
1616
* `Hash#merge` now preserves the key order from the original hash for merged values (#1650).
1717

1818
# 1.0 RC 17
@@ -41,7 +41,7 @@ Changes:
4141
Bug fixes:
4242

4343
* Fixed `Hash#merge` with no arguments to return a new copy of the receiver (#1645).
44-
* Fixed yield with a splat and keyword arguments (#1613).
44+
* Fixed yield with a splat and keyword arguments (#1613).
4545
* Fixed `rb_scan_args` to correctly handle kwargs in combination with optional args.
4646
* Many fixes for `FFI::Pointer` to be more compatible with the `ffi` gem.
4747

@@ -63,7 +63,6 @@ Compatibility:
6363
* `StringScanner` will now match a regexp beginning with `^` even when not scanning from the start of the string.
6464
* `Module#define_method` is now public like in MRI.
6565
* `Kernel#warn` now supports the `uplevel:` keyword argument.
66-
* `String#-@` now performs string deduplication (#1608) .
6766

6867
# 1.0 RC 15, 5 April 2019
6968

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,9 @@ def +@
15911591

15921592
def -@
15931593
str = frozen? ? self : dup.freeze
1594-
unless str.tainted? || !(str.instance_variables).empty?
1594+
if str.tainted? || !(str.instance_variables).empty?
1595+
str
1596+
else
15951597
Truffle::Ropes.flatten_rope(str)
15961598
Truffle.invoke_primitive(:string_intern, str)
15971599
end

0 commit comments

Comments
 (0)