summaryrefslogtreecommitdiff
path: root/spec/ruby/core/marshal
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2019-11-27 11:40:18 +0000
committerYusuke Endoh <mame@ruby-lang.org>2020-01-15 10:38:47 +0900
commit98ef38ada43338c073f50a0093196f0356284625 (patch)
tree1e7bdf0b54f4745501b9f3aed8ac44132ab6d25b /spec/ruby/core/marshal
parent07aef4c99ac4be3073f8b15ebdfa324a7f94f5e3 (diff)
Freeze Regexp literals
[Feature #8948] [Feature #16377] Since Regexp literals always reference the same instance, allowing to mutate them can lead to state leak.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2705
Diffstat (limited to 'spec/ruby/core/marshal')
-rw-r--r--spec/ruby/core/marshal/dump_spec.rb4
-rw-r--r--spec/ruby/core/marshal/shared/load.rb2
2 files changed, 3 insertions, 3 deletions
diff --git a/spec/ruby/core/marshal/dump_spec.rb b/spec/ruby/core/marshal/dump_spec.rb
index fc78ca4ff9..ea021991a8 100644
--- a/spec/ruby/core/marshal/dump_spec.rb
+++ b/spec/ruby/core/marshal/dump_spec.rb
@@ -235,13 +235,13 @@ describe "Marshal.dump" do
end
it "dumps a Regexp with instance variables" do
- o = //
+ o = Regexp.new("")
o.instance_variable_set(:@ivar, :ivar)
Marshal.dump(o).should == "\x04\bI/\x00\x00\a:\x06EF:\n@ivar:\tivar"
end
it "dumps an extended Regexp" do
- Marshal.dump(//.extend(Meths)).should == "\x04\bIe:\nMeths/\x00\x00\x06:\x06EF"
+ Marshal.dump(Regexp.new("").extend(Meths)).should == "\x04\bIe:\nMeths/\x00\x00\x06:\x06EF"
end
it "dumps a Regexp subclass" do
diff --git a/spec/ruby/core/marshal/shared/load.rb b/spec/ruby/core/marshal/shared/load.rb
index 302d3d5bda..78fc9fb286 100644
--- a/spec/ruby/core/marshal/shared/load.rb
+++ b/spec/ruby/core/marshal/shared/load.rb
@@ -623,7 +623,7 @@ describe :marshal_load, shared: true do
describe "for a Regexp" do
it "loads an extended Regexp" do
- obj = /[a-z]/.extend(Meths, MethsMore)
+ obj = /[a-z]/.dup.extend(Meths, MethsMore)
new_obj = Marshal.send(@method, "\004\be:\nMethse:\016MethsMore/\n[a-z]\000")
new_obj.should == obj