public
Created

psych doesn't handle instance variables in subclasses of Hash

  • Download Gist
test_hash.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
diff --git a/test/psych/test_hash.rb b/test/psych/test_hash.rb
index 4bd4edf..b000226 100644
--- a/test/psych/test_hash.rb
+++ b/test/psych/test_hash.rb
@@ -5,6 +5,10 @@ module Psych
class X < Hash
end
+ class Y < Hash
+ attr_accessor :val
+ end
+
def setup
super
@hash = { :a => 'b' }
@@ -16,6 +20,12 @@ module Psych
assert_equal X, x.class
end
+ def test_subclass_with_attributes
+ y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
+ assert_equal Y, y.class
+ assert_equal 1, y.val
+ end
+
def test_map
x = Psych.load "--- !map:#{X} { }\n"
assert_equal X, x.class

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.