diff --git a/ChangeLog b/ChangeLog index 384f958961..a83ef7ea2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Wed May 16 05:11:29 2012 Aaron Patterson + + * ext/psych/lib/psych/visitors/to_ruby.rb: fix a bug with string + subclass dumping and loading. + + * test/psych/test_array.rb: pertinent tests + + * test/psych/test_string.rb: ditto + Wed May 16 01:31:21 2012 Aaron Patterson * ext/psych/lib/psych/visitors/to_ruby.rb: convert omap tagged maps to diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index 26da83b8e1..eb4bab7513 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/lib/psych/visitors/to_ruby.rb @@ -147,8 +147,7 @@ module Psych string = members.delete 'str' if klass - string = klass.allocate - string.replace string + string = klass.allocate.replace string end init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o) diff --git a/test/psych/test_array.rb b/test/psych/test_array.rb index 9eedbb4fda..747fe95062 100644 --- a/test/psych/test_array.rb +++ b/test/psych/test_array.rb @@ -14,6 +14,16 @@ module Psych @list = [{ :a => 'b' }, 'foo'] end + def test_another_subclass_with_attributes + y = Y.new.tap {|y| y.val = 1} + y << "foo" << "bar" + y = Psych.load Psych.dump y + + assert_equal %w{foo bar}, y + assert_equal Y, y.class + assert_equal 1, y.val + end + def test_subclass yaml = Psych.dump X.new assert_match X.name, yaml diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index c7d5c60623..77aefc6dae 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -9,6 +9,13 @@ module Psych attr_accessor :val end + def test_another_subclass_with_attributes + y = Psych.load Psych.dump Y.new("foo").tap {|y| y.val = 1} + assert_equal "foo", y + assert_equal Y, y.class + assert_equal 1, y.val + end + def test_backwards_with_syck x = Psych.load "--- !str:#{X.name} foo\n\n" assert_equal X, x.class