summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2023-11-28 13:50:05 -0500
committerPeter Zhu <[email protected]>2023-11-29 19:21:40 -0500
commit3d908a41ab67e2aeced7dc6b9773a017bb859253 (patch)
tree3c898e637943bb17495bb347baae07e8789d1dab /test
parent8d1138c1cf087f28510f4532c746e70c54d0f81e (diff)
Guard match from GC in String#gsub
We need to guard match from GC because otherwise it could end up being reclaimed or moved in compaction.
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_string.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index fdf23ad90b..2ccabcbe80 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -1249,6 +1249,10 @@ CODE
assert_raise(ArgumentError) { S("foo").gsub }
end
+ def test_gsub_gc_compact_stress
+ EnvUtil.under_gc_compact_stress { assert_equal(S("h<e>ll<o>"), S("hello").gsub(/([aeiou])/, S('<\1>'))) }
+ end
+
def test_gsub_encoding
a = S("hello world")
a.force_encoding Encoding::UTF_8
@@ -1292,6 +1296,14 @@ CODE
assert_nil(a.sub!(S('X'), S('Y')))
end
+ def test_gsub_bang_gc_compact_stress
+ EnvUtil.under_gc_compact_stress do
+ a = S("hello")
+ a.gsub!(/([aeiou])/, S('<\1>'))
+ assert_equal(S("h<e>ll<o>"), a)
+ end
+ end
+
def test_sub_hash
assert_equal('azc', S('abc').sub(/b/, "b" => "z"))
assert_equal('ac', S('abc').sub(/b/, {}))