ruby-changes:20146
From: tenderlove <ko1@a...>
Date: Wed, 22 Jun 2011 03:23:08 +0900 (JST)
Subject: [ruby-changes:20146] tenderlove:r32194 (trunk): * ext/psych/lib/psych/visitors/to_ruby.rb: Fix cyclic references of
tenderlove 2011-06-22 03:22:54 +0900 (Wed, 22 Jun 2011) New Revision: 32194 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32194 Log: * ext/psych/lib/psych/visitors/to_ruby.rb: Fix cyclic references of objects. Thanks to CvX for reporting the bug and a test case. * test/psych/test_object.rb: test for cyclic object references. Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/visitors/to_ruby.rb trunk/test/psych/test_object.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 32193) +++ ChangeLog (revision 32194) @@ -1,3 +1,9 @@ +Wed Jun 22 03:20:52 2011 Aaron Patterson <aaron@t...> + + * ext/psych/lib/psych/visitors/to_ruby.rb: Fix cyclic references of + objects. Thanks to CvX for reporting the bug and a test case. + * test/psych/test_object.rb: test for cyclic object references. + Wed Jun 22 02:39:54 2011 Hiroshi Nakamura <nahi@r...> * lib/net/http.rb (Net::HTTP.post_form): Do not ignore query part of Index: ext/psych/lib/psych/visitors/to_ruby.rb =================================================================== --- ext/psych/lib/psych/visitors/to_ruby.rb (revision 32193) +++ ext/psych/lib/psych/visitors/to_ruby.rb (revision 32194) @@ -182,7 +182,6 @@ when /^!ruby\/object:?(.*)?$/ name = $1 || 'Object' obj = revive((resolve_class(name) || Object), o) - @st[o.anchor] = obj if o.anchor obj when /^!map:(.*)$/, /^!ruby\/hash:(.*)$/ @@ -233,6 +232,7 @@ def revive klass, node s = klass.allocate + @st[node.anchor] = s if node.anchor h = Hash[*node.children.map { |c| accept c }] init_with(s, h, node) end Index: test/psych/test_object.rb =================================================================== --- test/psych/test_object.rb (revision 32193) +++ test/psych/test_object.rb (revision 32194) @@ -11,6 +11,14 @@ end end + class Foo + attr_accessor :parent + + def initialize parent + @parent = parent + end + end + class TestObject < TestCase def test_dump_with_tag tag = Tagged.new @@ -23,5 +31,14 @@ assert_equal tag.baz, tag2.baz assert_instance_of(Tagged, tag2) end + + def test_cyclic_references + foo = Foo.new(nil) + foo.parent = foo + loaded = Psych.load Psych.dump foo + + assert_instance_of(Foo, loaded) + assert_equal loaded, loaded.parent + end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/