diff options
author | Steven Danna <steve@opscode.com> | 2014-02-08 20:21:03 -0800 |
---|---|---|
committer | Bryan McLellan <btm@getchef.com> | 2014-03-19 17:10:32 -0700 |
commit | dcfc7270c1960541ffd11eb81eb2d81d5d1f3eab (patch) | |
tree | 6ce4327624fac5f43bd1838a4ccd744ed4930b58 /lib | |
parent | c8bb17a34da8a35e4e4252c7c29951596b6e9678 (diff) | |
download | chef-dcfc7270c1960541ffd11eb81eb2d81d5d1f3eab.tar.gz |
[CHEF-4918] Don't destructively merge subhashes in hash_only_merge!
hash_only_merge dups its inputs and then passes it to
hash_only_merge!. Unfortunately, dup does not make a deep copy,
leading hash_only_merge to mutate deeply nested structures.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/mixin/deep_merge.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/chef/mixin/deep_merge.rb b/lib/chef/mixin/deep_merge.rb index ad3e5803fd..5002f5dcc5 100644 --- a/lib/chef/mixin/deep_merge.rb +++ b/lib/chef/mixin/deep_merge.rb @@ -122,7 +122,11 @@ class Chef # If there are two Hashes, recursively merge. if merge_onto.kind_of?(Hash) && merge_with.kind_of?(Hash) merge_with.each do |key, merge_with_value| - merge_onto[key] = hash_only_merge!(merge_onto[key], merge_with_value) + merge_onto[key] = if merge_onto.has_key?(key) + hash_only_merge(merge_onto[key], merge_with_value) + else + merge_with_value + end end merge_onto @@ -164,5 +168,3 @@ class Chef end end end - - |