Skip to content

Commit bc5acbe

Browse files
committed
Fix an issue where DeepMerge overwrites nil values
When run against a VividMash. Call .key? instead of [] when checking if a key exists for a VividMash Otherwise the VividMash will return an empty object instead of nil for that key. Signed-off-by: DJ Mountney <[email protected]>
1 parent 7372d0e commit bc5acbe

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/chef/mixin/deep_merge.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def deep_merge!(source, dest)
6464
when Hash
6565
if dest.kind_of?(Hash)
6666
source.each do |src_key, src_value|
67-
if dest[src_key]
67+
if dest.key?(src_key)
6868
dest[src_key] = deep_merge!(src_value, dest[src_key])
6969
else # dest[src_key] doesn't exist so we take whatever source has
7070
dest[src_key] = src_value

spec/unit/node_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,13 @@
337337
node.override_unless[:decontamination] = "foo"
338338
expect(node.override[:decontamination]).to eql("foo")
339339
end
340+
341+
it "consume_attributes does not exhibit chef/chef/issues/6302 bug" do
342+
node.normal["a"]["r1"] = nil
343+
node.consume_attributes({"a" => { "r2" => nil}})
344+
expect(node["a"]["r1"]).to be_nil
345+
expect(node["a"]["r2"]).to be_nil
346+
end
340347
end
341348

342349
describe "default attributes" do

0 commit comments

Comments
 (0)