summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-12 00:00:12 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-12 00:00:12 +0000
commit0a60805af583612439750e3ae2e168bf183f6e84 (patch)
tree49830e33906b3f2dfadd134b402a19ee1ee8d484
parent92a7da1900323139bb678dcde62a8c821cf301f9 (diff)
* ext/psych/lib/psych/visitors/to_ruby.rb: merge key values that
contain something besides a hash should be left in tact. * test/psych/test_merge_keys.rb: test for change git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--ext/psych/lib/psych/visitors/to_ruby.rb26
-rw-r--r--test/psych/test_merge_keys.rb51
3 files changed, 78 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 4686d4b..574b923 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sat Jan 12 08:58:47 2013 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * ext/psych/lib/psych/visitors/to_ruby.rb: merge key values that
+ contain something besides a hash should be left in tact.
+
+ * test/psych/test_merge_keys.rb: test for change
+
Sat Jan 12 07:52:47 2013 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (ole_set_byref): support VT_UI8|VT_BYREF,
diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb
index 725f1f9..9ccf420 100644
--- a/ext/psych/lib/psych/visitors/to_ruby.rb
+++ b/ext/psych/lib/psych/visitors/to_ruby.rb
@@ -263,28 +263,42 @@ module Psych
def revive_hash hash, o
@st[o.anchor] = hash if o.anchor
- o.children.each_slice(2) { |k,v|
+ o.children.each_slice(2) { |k,v|
key = accept(k)
+ val = accept(v)
if key == '<<'
case v
when Nodes::Alias
- hash.merge! accept(v)
+ begin
+ hash.merge! val
+ rescue TypeError
+ hash[key] = val
+ end
when Nodes::Sequence
- accept(v).reverse_each do |value|
- hash.merge! value
+ begin
+ h = {}
+ val.reverse_each do |value|
+ h.merge! value
+ end
+ hash.merge! h
+ rescue TypeError
+ hash[key] = val
end
else
- hash[key] = accept(v)
+ hash[key] = val
end
else
- hash[key] = accept(v)
+ hash[key] = val
end
}
hash
end
+ def merge_key hash, key, val
+ end
+
def revive klass, node
s = klass.allocate
@st[node.anchor] = s if node.anchor
diff --git a/test/psych/test_merge_keys.rb b/test/psych/test_merge_keys.rb
index bf5968f..c31f9b8 100644
--- a/test/psych/test_merge_keys.rb
+++ b/test/psych/test_merge_keys.rb
@@ -2,6 +2,57 @@ require 'psych/helper'
module Psych
class TestMergeKeys < TestCase
+ def test_merge_nil
+ yaml = <<-eoyml
+defaults: &defaults
+development:
+ <<: *defaults
+ eoyml
+ assert_equal({'<<' => nil }, Psych.load(yaml)['development'])
+ end
+
+ def test_merge_array
+ yaml = <<-eoyml
+foo: &hello
+- 1
+baz:
+ <<: *hello
+ eoyml
+ assert_equal({'<<' => [1]}, Psych.load(yaml)['baz'])
+ end
+
+ def test_merge_is_not_partial
+ yaml = <<-eoyml
+default: &default
+ hello: world
+foo: &hello
+- 1
+baz:
+ <<: [*hello, *default]
+ eoyml
+ doc = Psych.load yaml
+ refute doc['baz'].key? 'hello'
+ assert_equal({'<<' => [[1], {"hello"=>"world"}]}, Psych.load(yaml)['baz'])
+ end
+
+ def test_merge_seq_nil
+ yaml = <<-eoyml
+foo: &hello
+baz:
+ <<: [*hello]
+ eoyml
+ assert_equal({'<<' => [nil]}, Psych.load(yaml)['baz'])
+ end
+
+ def test_bad_seq_merge
+ yaml = <<-eoyml
+defaults: &defaults [1, 2, 3]
+development:
+ <<: *defaults
+ eoyml
+ assert_equal({'<<' => [1,2,3]}, Psych.load(yaml)['development'])
+ end
+
def test_missing_merge_key
yaml = <<-eoyml
bar: