summaryrefslogtreecommitdiff
path: root/spec/ruby
diff options
context:
space:
mode:
authorNARUSE, Yui <naruse@airemix.jp>2023-03-08 14:46:30 +0900
committerNARUSE, Yui <naruse@airemix.jp>2023-03-08 14:46:30 +0900
commit4e4a4e42b284d9309a7e51c97058093539e7a843 (patch)
treece2710dc195ee49e8f41de8b2b68af9b4ca50b23 /spec/ruby
parent59eb18037ff92839be48fb6c46ff0acc179b4f4c (diff)
merge revision(s) d2520b7b76759118071a16e6bca22726a5de9fb4: [Backport #19439]
Marshal.load: restore instance variables on Regexp [Bug #19439] The instance variables were restore on the Regexp source, not the regexp itself. Unfortunately we have a bit of a chicken and egg problem. The source holds the encoding, and the encoding need to be set on the source to be able to instantiate the Regexp. So the instance variables have to be read on the `source`. To correct this we transfert the instance variables after instantiating the Regexp. The only way to avoid this would be to read the instance variable twice and rewind. --- marshal.c | 20 ++++++++++++++++++-- spec/ruby/core/marshal/shared/load.rb | 11 +++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-)
Diffstat (limited to 'spec/ruby')
-rw-r--r--spec/ruby/core/marshal/shared/load.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/spec/ruby/core/marshal/shared/load.rb b/spec/ruby/core/marshal/shared/load.rb
index 98fae44296..479c7477ec 100644
--- a/spec/ruby/core/marshal/shared/load.rb
+++ b/spec/ruby/core/marshal/shared/load.rb
@@ -720,6 +720,17 @@ describe :marshal_load, shared: true do
new_obj_metaclass_ancestors[@num_self_class, 3].should ==
[Meths, UserRegexp, Regexp]
end
+
+ ruby_bug "#19439", ""..."3.3" do
+ it "restore the regexp instance variables" do
+ obj = Regexp.new("hello")
+ obj.instance_variable_set(:@regexp_ivar, [42])
+
+ new_obj = Marshal.send(@method, "\x04\bI/\nhello\x00\a:\x06EF:\x11@regexp_ivar[\x06i/")
+ new_obj.instance_variables.should == [:@regexp_ivar]
+ new_obj.instance_variable_get(:@regexp_ivar).should == [42]
+ end
+ end
end
describe "for a Float" do