aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--string.c3
-rw-r--r--test/-ext-/string/test_capacity.rb19
2 files changed, 22 insertions, 0 deletions
diff --git a/string.c b/string.c
index 030465235a..8ac33e3e52 100644
--- a/string.c
+++ b/string.c
@@ -321,6 +321,9 @@ rb_fstring(VALUE str)
return str;
}
+ if (!OBJ_FROZEN(str))
+ rb_str_resize(str, RSTRING_LEN(str));
+
fstr = register_fstring(str);
if (!bare) {
diff --git a/test/-ext-/string/test_capacity.rb b/test/-ext-/string/test_capacity.rb
index 65444123a7..df59e76778 100644
--- a/test/-ext-/string/test_capacity.rb
+++ b/test/-ext-/string/test_capacity.rb
@@ -37,4 +37,23 @@ class Test_StringCapacity < Test::Unit::TestCase
open(__FILE__) {|f|s = f.read(1024*1024)}
assert_operator(capa(s), :<=, s.bytesize+4096)
end
+
+ def test_literal_capacity
+ s = "I am testing string literal capacity"
+ assert_equal(s.length, capa(s))
+ end
+
+ def test_capacity_frozen
+ s = String.new("I am testing", capacity: 1000)
+ s << "fstring capacity"
+ s.freeze
+ assert_equal(s.length, capa(s))
+ end
+
+ def test_capacity_fstring
+ s = String.new("I am testing", capacity: 1000)
+ s << "fstring capacity"
+ s = -s
+ assert_equal(s.length, capa(s))
+ end
end