From fdd7ffb70ca6e9f7d790aadde86dbc8172e19f4d Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 25 Mar 2024 09:24:21 +0900 Subject: [PATCH] [Bug #20389] Chilled string cannot be a shared root --- string.c | 2 +- test/ruby/test_string.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/string.c b/string.c index cbd8f90585..9d84b16a07 100644 --- a/string.c +++ b/string.c @@ -1340,7 +1340,7 @@ rb_str_new_shared(VALUE str) VALUE rb_str_new_frozen(VALUE orig) { - if (OBJ_FROZEN(orig)) return orig; + if (RB_FL_TEST_RAW(orig, FL_FREEZE | STR_CHILLED) == FL_FREEZE) return orig; return str_new_frozen(rb_obj_class(orig), orig); } diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 8df6d3277f..8ec80d06fc 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -3648,6 +3648,18 @@ CODE Warning[:deprecated] = deprecated end + def test_chilled_string_substring + deprecated = Warning[:deprecated] + Warning[:deprecated] = false + chilled_string = eval('"a chilled string."') + substring = chilled_string[0..-1] + assert_equal("a chilled string.", substring) + chilled_string[0..-1] = "This string is defrosted." + assert_equal("a chilled string.", substring) + ensure + Warning[:deprecated] = deprecated + end + private def assert_bytesplice_result(expected, s, *args)