diff options
-rw-r--r-- | lib/puppet/parser/functions/delete_values.rb | 2 | ||||
-rw-r--r-- | spec/unit/puppet/parser/functions/delete_values_spec.rb | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/puppet/parser/functions/delete_values.rb b/lib/puppet/parser/functions/delete_values.rb index 17b9d37..ca8eef5 100644 --- a/lib/puppet/parser/functions/delete_values.rb +++ b/lib/puppet/parser/functions/delete_values.rb @@ -21,6 +21,6 @@ Would return: {'a'=>'A','c'=>'C','B'=>'D'} raise(TypeError, "delete_values(): First argument must be a Hash. " + \ "Given an argument of class #{hash.class}.") end - hash.delete_if { |key, val| item == val } + hash.dup.delete_if { |key, val| item == val } end end 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 |