Skip to content

Commit 2d6af95

Browse files
committed
[GR-19220] Fix String#scrub! (#2249)
PullRequest: truffleruby/2395
2 parents c5159ce + 0754e88 commit 2d6af95

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

spec/ruby/core/string/scrub_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,18 @@
105105
input.scrub! { |b| "<?>" }
106106
input.should == "a<?>"
107107
end
108+
109+
it "maintains the state of frozen strings that are already valid" do
110+
input = "a"
111+
input.freeze
112+
input.scrub!
113+
input.frozen?.should be_true
114+
end
115+
116+
it "preserves the instance variables of already valid strings" do
117+
input = "a"
118+
input.instance_variable_set(:@a, 'b')
119+
input.scrub!
120+
input.instance_variable_get(:@a).should == 'b'
121+
end
108122
end

src/main/ruby/truffleruby/core/string.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,7 @@ def scrub(replace = nil, &block)
10191019
end
10201020

10211021
def scrub!(replace = nil, &block)
1022+
return self if valid_encoding?
10221023
replace(scrub(replace, &block))
10231024
self
10241025
end

0 commit comments

Comments
 (0)