diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-08-29 14:12:20 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-08-29 14:12:20 -0700 |
commit | 854c567fc73419f0c48f8e4dc5da061fe7bc10b5 (patch) | |
tree | 504b89821e4e003431dfef9af766e5607b15a9be | |
parent | 08092b0f089f914388bfdf4775fb260a80ef7361 (diff) | |
download | psych-854c567fc73419f0c48f8e4dc5da061fe7bc10b5.tar.gz |
* ext/psych/lib/psych/visitors/to_ruby.rb: merge keys with a hash
should merge the hash in to the parent.
* test/psych/test_merge_keys.rb: test for change. Fixes GH #202
Fixes #202
-rw-r--r-- | CHANGELOG.rdoc | 6 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 2 | ||||
-rw-r--r-- | test/psych/test_merge_keys.rb | 10 |
3 files changed, 17 insertions, 1 deletions
diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index fa8bb2e..96b528b 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,3 +1,9 @@ +Sat Aug 30 06:10:39 2014 Aaron Patterson <aaron@tenderlovemaking.com> + + * ext/psych/lib/psych/visitors/to_ruby.rb: merge keys with a hash + should merge the hash in to the parent. + * test/psych/test_merge_keys.rb: test for change. Fixes GH #202 + Sat Aug 30 06:00:26 2014 Aaron Patterson <aaron@tenderlovemaking.com> * ext/psych/lib/psych/visitors/to_ruby.rb: quoted "<<" strings diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index 984bc84..e74d5d4 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -307,7 +307,7 @@ module Psych if key == '<<' && k.tag != "tag:yaml.org,2002:str" case v - when Nodes::Alias + when Nodes::Alias, Nodes::Mapping begin hash.merge! val rescue TypeError diff --git a/test/psych/test_merge_keys.rb b/test/psych/test_merge_keys.rb index 8b263e5..1620a6a 100644 --- a/test/psych/test_merge_keys.rb +++ b/test/psych/test_merge_keys.rb @@ -6,6 +6,16 @@ module Psych attr_reader :bar end + def test_merge_key_with_bare_hash + doc = Psych.load <<-eodoc +map: + <<: + hello: world + eodoc + hash = { "map" => { "hello" => "world" } } + assert_equal hash, doc + end + def test_roundtrip_with_chevron_key h = {} v = { 'a' => h, '<<' => h } |