summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid T. Crosby <dtcrsby@gmail.com>2023-05-10 06:34:02 -0600
committerGitHub <noreply@github.com>2023-05-10 08:34:02 -0400
commit42a076b15384dc4451dfbd0026c6b8d31d0774c1 (patch)
tree61fe11489719a08e2c6d1fd352f63386917d1055
parent9209938dbf5371ab2cc07c67d9dd29d4274ae216 (diff)
downloadchef-42a076b15384dc4451dfbd0026c6b8d31d0774c1.tar.gz
Fix case statement ordering in convert_value (#13733)
Signed-off-by: David Crosby <dcrosby@fb.com>
-rw-r--r--lib/chef/node/immutable_collections.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb
index 79b1983a05..a5def9ba3b 100644
--- a/lib/chef/node/immutable_collections.rb
+++ b/lib/chef/node/immutable_collections.rb
@@ -32,13 +32,16 @@ class Chef
end
def convert_value(value)
+ # The order in this case statement is *important*.
+ # ImmutableMash and ImmutableArray should be tested first,
+ # as this saves unnecessary creation of intermediate objects
case value
+ when ImmutableMash, ImmutableArray
+ value
when Hash
ImmutableMash.new(value, __root__, __node__, __precedence__)
when Array
ImmutableArray.new(value, __root__, __node__, __precedence__)
- when ImmutableMash, ImmutableArray
- value
else
safe_dup(value).freeze
end