summaryrefslogtreecommitdiff
path: root/lib/chef/node
diff options
context:
space:
mode:
authorGiacomo Bagnoli <gbagnoli@gmail.com>2016-09-20 15:15:08 +0100
committerGiacomo Bagnoli <gbagnoli@gmail.com>2016-09-21 15:58:07 +0100
commit39774946fbbd8b1f7d3267df3fcb7369ad5cac6d (patch)
treeb675e2919c982bc8a9fe0e50ef15d4a9a55c5e16 /lib/chef/node
parentce694677fdc808143a28457dc44d56e97930b9ec (diff)
downloadchef-39774946fbbd8b1f7d3267df3fcb7369ad5cac6d.tar.gz
Convert attributes defined as literal arrays
VividMash, unlike Mash, does not recursively convert values inside arrays, just the array itself. As such, hashes inside arrays are not converted to *Mash, introducing a behaviour that differs from Chef 11, e.g. having this attr defined node['foo'] = [ { 'attr' => 'value' } ] in Chef 11 `node[:foo][0][:attr]` returns `'value'` while in Chef 12 it returns `nil` This commit fixes VividMash so arrays are recursively converted and the behaviour restored. Plus, immutablize merge_all result, so to be sure that hashes contained in Arrays are properly immutablized as well, so not existing attributes are not automatically vivified (thus returning an empty VividMash instead of nil) This problem was first reported in chef/chef#2871. Signed-off-by: Giacomo Bagnoli <gbagnoli@gmail.com>
Diffstat (limited to 'lib/chef/node')
-rw-r--r--lib/chef/node/attribute.rb4
-rw-r--r--lib/chef/node/attribute_collections.rb2
2 files changed, 2 insertions, 4 deletions
diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb
index 95b3b09f7e..a4a07275c0 100644
--- a/lib/chef/node/attribute.rb
+++ b/lib/chef/node/attribute.rb
@@ -452,9 +452,7 @@ class Chef
#
def merged_attributes(*path)
- # immutablize(
- merge_all(path)
- # )
+ immutablize(merge_all(path))
end
def combined_override(*path)
diff --git a/lib/chef/node/attribute_collections.rb b/lib/chef/node/attribute_collections.rb
index b739ea8490..b36d4a1540 100644
--- a/lib/chef/node/attribute_collections.rb
+++ b/lib/chef/node/attribute_collections.rb
@@ -187,7 +187,7 @@ class Chef
when Hash
VividMash.new(root, value)
when Array
- AttrArray.new(root, value)
+ AttrArray.new(root, value.map { |e| convert_value(e) })
else
value
end