From 51d96088c1d6bde8dae511d6a93bc6775e716f60 Mon Sep 17 00:00:00 2001 From: Leonardo Rodrigues de Mello Date: Mon, 16 Sep 2013 10:33:58 -0300 Subject: (#20681) fix behaviour of delete_values The issue #20681 describe the error of delete() function removing the elements from the origin array/hash/string. This issue affected other delete functions. Because ruby delete and delete_if functions make destructive changes to the origin array/hash. The delete_undef_values removed elements from the origin hash and this is not the desired behaviour. To solve this, we should dup or clone the hash before using the delete or delete_if ruby functions. This fix the problem and add unit tests, so we could enforce this behaviour and prevent regressions. --- spec/unit/puppet/parser/functions/delete_values_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec') diff --git a/spec/unit/puppet/parser/functions/delete_values_spec.rb b/spec/unit/puppet/parser/functions/delete_values_spec.rb index c62e55f..180cc30 100644 --- a/spec/unit/puppet/parser/functions/delete_values_spec.rb +++ b/spec/unit/puppet/parser/functions/delete_values_spec.rb @@ -27,4 +27,10 @@ describe "the delete_values function" do result.should(eq({ 'a'=>'A', 'B'=>'C' })) end + it "should not change origin hash passed as argument" do + origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 } + result = scope.function_delete_values([origin_hash, 2]) + origin_hash.should(eq({ 'a' => 1, 'b' => 2, 'c' => 3 })) + end + end -- cgit v1.2.3