summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-22 08:09:44 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-22 08:09:44 +0000
commit67b180748b7e8e551f46a072013162db83ac703f (patch)
treeda0c62f118ff38fb0a5e7992c4c06f409584b47d /test
parent16dc6c29554d9ea0cc3c01592646cceec827bba3 (diff)
marshal.c: fix marshal_load ivar
* marshal.c (r_object0): copy all instance variables not only generic ivars, before calling post proc. [ruby-core:51163] [Bug #7627] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40408 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_marshal.rb28
1 files changed, 26 insertions, 2 deletions
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb
index a642385a8e..d7afec3f66 100644
--- a/test/ruby/test_marshal.rb
+++ b/test/ruby/test_marshal.rb
@@ -538,16 +538,23 @@ class TestMarshal < Test::Unit::TestCase
assert_nil(loaded.foo, bug7627)
end
- class Bug8276
+ class LoadData
attr_reader :data
def initialize(data)
@data = data
- freeze
end
alias marshal_dump data
alias marshal_load initialize
end
+ class Bug8276 < LoadData
+ def initialize(*)
+ super
+ freeze
+ end
+ alias marshal_load initialize
+ end
+
def test_marshal_dump_excess_encoding
bug8276 = '[ruby-core:54334] [Bug #8276]'
t = Bug8276.new(bug8276)
@@ -564,6 +571,23 @@ class TestMarshal < Test::Unit::TestCase
assert_raise(RuntimeError) {Marshal.load(s)}
end
+ def test_marshal_load_ivar
+ s = "data with ivar"
+ s.instance_variable_set(:@t, 42)
+ t = LoadData.new(s)
+ s = Marshal.dump(t)
+ hook = ->(v) {
+ if LoadData === v
+ assert_send([v, :instance_variable_defined?, :@t])
+ assert_equal(42, v.instance_variable_get(:@t))
+ end
+ v
+ }
+ v = Marshal.load(s, hook)
+ assert_send([v, :instance_variable_defined?, :@t])
+ assert_equal(42, v.instance_variable_get(:@t))
+ end
+
def test_class_ivar
assert_raise(TypeError) {Marshal.load("\x04\x08Ic\x1bTestMarshal::TestClass\x06:\x0e@ivar_bug\"\x08bug")}
assert_raise(TypeError) {Marshal.load("\x04\x08IM\x1bTestMarshal::TestClass\x06:\x0e@ivar_bug\"\x08bug")}