summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMalte Swart <chef@malteswart.de>2013-04-16 23:39:59 +0200
committerLamont Granquist <lamont@scriptkiddie.org>2014-08-23 10:23:46 -0700
commit972bc2f61685979e5b76f5481e3b1af2bd010d0e (patch)
tree782325dd308823965325dcf7b52d9587c9fd667c /lib
parent45e8bf3c416dff31d133a2ff8844bbbf63fb0c80 (diff)
downloadchef-972bc2f61685979e5b76f5481e3b1af2bd010d0e.tar.gz
CHEF-4101: DeepMerge - support overwriting hash values with nil
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/mixin/deep_merge.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/chef/mixin/deep_merge.rb b/lib/chef/mixin/deep_merge.rb
index a8a4737758..5e3327a526 100644
--- a/lib/chef/mixin/deep_merge.rb
+++ b/lib/chef/mixin/deep_merge.rb
@@ -29,7 +29,6 @@ class Chef
class InvalidSubtractiveMerge < ArgumentError; end
-
OLD_KNOCKOUT_PREFIX = "!merge:".freeze
# Regex to match the "knockout prefix" that was used to indicate
@@ -86,8 +85,12 @@ class Chef
when Hash
if dest.kind_of?(Hash)
source.each do |src_key, src_value|
- if dest[src_key]
- dest[src_key] = deep_merge!(src_value, dest[src_key])
+ 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
else # dest[src_key] doesn't exist so we take whatever source has
raise_if_knockout_used!(src_value)
dest[src_key] = src_value