Skip to content

Commit 53728be

Browse files
committed
Fix rb_str_locktmp and rb_str_unlocktmp to raise FrozenError when string is frozen
1 parent 5333871 commit 53728be

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

optional/capi/string_spec.rb

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,28 +1201,50 @@ def inspect
12011201

12021202
describe "rb_str_locktmp" do
12031203
it "raises an error when trying to lock an already locked string" do
1204-
str = "test"
1204+
str = +"test"
12051205
@s.rb_str_locktmp(str).should == str
12061206
-> { @s.rb_str_locktmp(str) }.should raise_error(RuntimeError, 'temporal locking already locked string')
12071207
end
12081208

12091209
it "locks a string so that modifications would raise an error" do
1210-
str = "test"
1210+
str = +"test"
12111211
@s.rb_str_locktmp(str).should == str
12121212
-> { str.upcase! }.should raise_error(RuntimeError, 'can\'t modify string; temporarily locked')
12131213
end
1214+
1215+
ruby_bug "#20998", ""..."3.5" do
1216+
it "raises FrozenError if string is frozen" do
1217+
str = -"rb_str_locktmp"
1218+
-> { @s.rb_str_locktmp(str) }.should raise_error(FrozenError)
1219+
1220+
str = +"rb_str_locktmp"
1221+
str.freeze
1222+
-> { @s.rb_str_locktmp(str) }.should raise_error(FrozenError)
1223+
end
1224+
end
12141225
end
12151226

12161227
describe "rb_str_unlocktmp" do
12171228
it "unlocks a locked string" do
1218-
str = "test"
1229+
str = +"test"
12191230
@s.rb_str_locktmp(str)
12201231
@s.rb_str_unlocktmp(str).should == str
12211232
str.upcase!.should == "TEST"
12221233
end
12231234

12241235
it "raises an error when trying to unlock an already unlocked string" do
1225-
-> { @s.rb_str_unlocktmp("test") }.should raise_error(RuntimeError, 'temporal unlocking already unlocked string')
1236+
-> { @s.rb_str_unlocktmp(+"test") }.should raise_error(RuntimeError, 'temporal unlocking already unlocked string')
1237+
end
1238+
1239+
ruby_bug "#20998", ""..."3.5" do
1240+
it "raises FrozenError if string is frozen" do
1241+
str = -"rb_str_locktmp"
1242+
-> { @s.rb_str_unlocktmp(str) }.should raise_error(FrozenError)
1243+
1244+
str = +"rb_str_locktmp"
1245+
str.freeze
1246+
-> { @s.rb_str_unlocktmp(str) }.should raise_error(FrozenError)
1247+
end
12261248
end
12271249
end
12281250

0 commit comments

Comments
 (0)