diff options
author | Serdar Sutay <serdar@opscode.com> | 2014-11-08 20:31:19 -0800 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2014-11-08 20:31:19 -0800 |
commit | 5ac565eaac581602115c18f0ed9b38b83bedcc31 (patch) | |
tree | a701d335775cdc06fa7d60608df69b55de3afd81 | |
parent | 5d7f05a0436b85929a0a764807fa81b26b3d4fb8 (diff) | |
parent | a47ba4d4b99eed8b0f606fe6a9794e0f559f69e4 (diff) | |
download | chef-5ac565eaac581602115c18f0ed9b38b83bedcc31.tar.gz |
Merge pull request #2387 from opscode/sersut/revert-attr-nil-override
Revert "CHEF-4101: DeepMerge - support overwriting hash values with nil"
-rw-r--r-- | lib/chef/mixin/deep_merge.rb | 9 | ||||
-rw-r--r-- | spec/unit/mixin/deep_merge_spec.rb | 14 |
2 files changed, 3 insertions, 20 deletions
diff --git a/lib/chef/mixin/deep_merge.rb b/lib/chef/mixin/deep_merge.rb index 5e3327a526..a8a4737758 100644 --- a/lib/chef/mixin/deep_merge.rb +++ b/lib/chef/mixin/deep_merge.rb @@ -29,6 +29,7 @@ class Chef class InvalidSubtractiveMerge < ArgumentError; end + OLD_KNOCKOUT_PREFIX = "!merge:".freeze # Regex to match the "knockout prefix" that was used to indicate @@ -85,12 +86,8 @@ class Chef when Hash if dest.kind_of?(Hash) source.each do |src_key, src_value| - if dest.has_key? src_key - if dest[src_key].nil? - dest[src_key] = nil - else - dest[src_key] = deep_merge!(src_value, dest[src_key]) - end + if dest[src_key] + dest[src_key] = deep_merge!(src_value, dest[src_key]) else # dest[src_key] doesn't exist so we take whatever source has raise_if_knockout_used!(src_value) dest[src_key] = src_value diff --git a/spec/unit/mixin/deep_merge_spec.rb b/spec/unit/mixin/deep_merge_spec.rb index 40e749ecc0..779445e04e 100644 --- a/spec/unit/mixin/deep_merge_spec.rb +++ b/spec/unit/mixin/deep_merge_spec.rb @@ -236,20 +236,6 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do @dm.deep_merge!(hash_src, hash_dst) expect(hash_dst).to eq({"item" => "orange"}) end - - it 'should overwrite hashes with nil' do - hash_src = {"item" => { "1" => "2"}, "other" => true } - hash_dst = {"item" => nil } - @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({"item" => nil, "other" => true }) - end - - it 'should overwrite strings with nil' do - hash_src = {"item" => "to_overwrite", "other" => false } - hash_dst = {"item" => nil } - @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({"item" => nil, "other" => false }) - end end # deep_merge! # Chef specific |