summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Owens <jkowens@gmail.com>2019-01-16 00:29:12 -0500
committerJordan Owens <jkowens@gmail.com>2019-01-16 00:29:12 -0500
commit616d3a8da466a67682f39368a9ad66851d0c70f3 (patch)
tree21a774f83b8040a64dd6aba4d3b1afd6061d6f6e
parent63c94cf4f1a877a84c9bbed2ccabc773f9e56035 (diff)
downloadpsych-616d3a8da466a67682f39368a9ad66851d0c70f3.tar.gz
Add test to demonstrate issue deserializing hash with ivar
Currently the elements of a hash are revived before any ivar values. This causes an issue when the `[]=` method references an instance variable.
-rw-r--r--test/psych/test_hash.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/psych/test_hash.rb b/test/psych/test_hash.rb
index e93aa73..2a563da 100644
--- a/test/psych/test_hash.rb
+++ b/test/psych/test_hash.rb
@@ -6,6 +6,18 @@ module Psych
class X < Hash
end
+ class HashWithIvar < Hash
+ def initialize
+ @keys = []
+ super
+ end
+
+ def []=(k, v)
+ @keys << k
+ super(k, v)
+ end
+ end
+
class HashWithCustomInit < Hash
attr_reader :obj
def initialize(obj)
@@ -24,6 +36,14 @@ module Psych
@hash = { :a => 'b' }
end
+ def test_hash_with_ivar
+ t1 = HashWithIvar.new
+ t1[:foo] = :bar
+ t2 = Psych.load(Psych.dump(t1))
+ assert_equal t1, t2
+ assert_cycle t1
+ end
+
def test_referenced_hash_with_ivar
a = [1,2,3,4,5]
t1 = [HashWithCustomInit.new(a)]