diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-01-08 22:15:20 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-01-08 22:15:20 +0000 |
commit | 5dabead1871ed0100674e3eeb4a9f549b1997a85 (patch) | |
tree | 224befd9530cbddacc71900bd29c71718506e70d | |
parent | 8c08c8298a03a01629a478b74abfd57d7f35cb05 (diff) | |
download | ruby-5dabead1871ed0100674e3eeb4a9f549b1997a85.tar.gz |
* ext/psych/lib/psych/visitors/to_ruby.rb: call `allocate` on hash
subclasses. Fixes github.com/tenderlove/psych/issues/196
* test/psych/test_hash.rb: test for change
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | ext/psych/lib/psych/visitors/to_ruby.rb | 4 | ||||
-rw-r--r-- | test/psych/test_hash.rb | 28 |
3 files changed, 37 insertions, 2 deletions
@@ -1,3 +1,10 @@ +Fri Jan 9 07:13:55 2015 Aaron Patterson <aaron@tenderlovemaking.com> + + * ext/psych/lib/psych/visitors/to_ruby.rb: call `allocate` on hash + subclasses. Fixes github.com/tenderlove/psych/issues/196 + + * test/psych/test_hash.rb: test for change + Fri Jan 9 06:58:43 2015 Aaron Patterson <aaron@tenderlovemaking.com> * ext/psych/lib/psych/visitors/to_ruby.rb: revive hashes with ivars diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index adf38a21e8..f353e9c301 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/lib/psych/visitors/to_ruby.rb @@ -262,7 +262,7 @@ module Psych set when /^!ruby\/hash-with-ivars(?::(.*))?$/ - hash = $1 ? resolve_class($1).new : {} + hash = $1 ? resolve_class($1).allocate : {} o.children.each_slice(2) do |key, value| case key.value when 'elements' @@ -276,7 +276,7 @@ module Psych hash when /^!map:(.*)$/, /^!ruby\/hash:(.*)$/ - revive_hash register(o, resolve_class($1).new), o + revive_hash register(o, resolve_class($1).allocate), o when '!omap', 'tag:yaml.org,2002:omap' map = register(o, class_loader.psych_omap.new) diff --git a/test/psych/test_hash.rb b/test/psych/test_hash.rb index 8d7ba1b1e0..066df6612e 100644 --- a/test/psych/test_hash.rb +++ b/test/psych/test_hash.rb @@ -5,11 +5,39 @@ module Psych class X < Hash end + class HashWithCustomInit < Hash + attr_reader :obj + def initialize(obj) + @obj = obj + end + end + + class HashWithCustomInitNoIvar < Hash + def initialize(obj) + # *shrug* + end + end + def setup super @hash = { :a => 'b' } end + def test_custom_initialized + a = [1,2,3,4,5] + t1 = HashWithCustomInit.new(a) + t2 = Psych.load(Psych.dump(t1)) + assert_equal t1, t2 + assert_cycle t1 + end + + def test_custom_initialize_no_ivar + t1 = HashWithCustomInitNoIvar.new(nil) + t2 = Psych.load(Psych.dump(t1)) + assert_equal t1, t2 + assert_cycle t1 + end + def test_hash_with_ivars @hash.instance_variable_set :@foo, 'bar' dup = Psych.load Psych.dump @hash |