diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-02-06 08:50:00 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-02-06 08:50:00 +0000 |
commit | ecbf8351808c2425ec081c9055c9ddd790933e8b (patch) | |
tree | a17351ae161e139351f1f4d9b0f1467c5763bdcd | |
parent | ef5b8fe12f2d1c4a24c71c7965b7e7184ad613d6 (diff) |
* ext/psych/lib/psych/visitors/yaml_tree.rb: register nodes when
dumping objects with custom coders. [ruby-core:66215] [Bug #10496]
* test/psych/test_coder.rb: test for fix
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49529 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | ext/psych/lib/psych/visitors/yaml_tree.rb | 7 | ||||
-rw-r--r-- | test/psych/test_coder.rb | 22 |
3 files changed, 33 insertions, 3 deletions
@@ -1,3 +1,10 @@ +Fri Feb 6 17:47:05 2015 Aaron Patterson <[email protected]> + + * ext/psych/lib/psych/visitors/yaml_tree.rb: register nodes when + dumping objects with custom coders. [ruby-core:66215] [Bug #10496] + + * test/psych/test_coder.rb: test for fix + Fri Feb 6 16:58:31 2015 Aaron Patterson <[email protected]> * ext/psych/lib/psych/visitors/to_ruby.rb: fix support for regular diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index 8841cb0fc9..e13fd774e8 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -21,6 +21,7 @@ module Psych end def register target, node + return unless target.respond_to? :object_id @targets << target @obj_to_node[target.object_id] = node end @@ -566,10 +567,10 @@ module Psych c = Psych::Coder.new(tag) o.encode_with(c) - emit_coder c + emit_coder c, o end - def emit_coder c + def emit_coder c, o case c.type when :scalar @emitter.scalar c.scalar, nil, c.tag, c.tag.nil?, false, Nodes::Scalar::ANY @@ -580,7 +581,7 @@ module Psych end @emitter.end_sequence when :map - @emitter.start_mapping nil, c.tag, c.implicit, c.style + register o, @emitter.start_mapping(nil, c.tag, c.implicit, c.style) c.map.each do |k,v| accept k accept v diff --git a/test/psych/test_coder.rb b/test/psych/test_coder.rb index 7571e89c9d..e3213e2faa 100644 --- a/test/psych/test_coder.rb +++ b/test/psych/test_coder.rb @@ -95,6 +95,28 @@ module Psych end end + class Referential + attr_reader :a + + def initialize + @a = self + end + + def encode_with(c) + c['a'] = @a + end + + def init_with(c) + @a = c['a'] + end + end + + def test_self_referential + x = Referential.new + copy = Psych.load Psych.dump x + assert_equal copy, copy.a + end + def test_represent_with_object thing = Psych.load(Psych.dump(RepresentWithObject.new)) assert_equal 20, thing |