Skip to content

Commit 1011670

Browse files
committed
Merge pull request #182 from lmello/fix_bug_20681_delete_values
delete_values() fix bug #20681.
2 parents f7f70fe + 51d9608 commit 1011670

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/puppet/parser/functions/delete_values.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ module Puppet::Parser::Functions
2121
raise(TypeError, "delete_values(): First argument must be a Hash. " + \
2222
"Given an argument of class #{hash.class}.")
2323
end
24-
hash.delete_if { |key, val| item == val }
24+
hash.dup.delete_if { |key, val| item == val }
2525
end
2626
end

spec/unit/puppet/parser/functions/delete_values_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@
2727
result.should(eq({ 'a'=>'A', 'B'=>'C' }))
2828
end
2929

30+
it "should not change origin hash passed as argument" do
31+
origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 }
32+
result = scope.function_delete_values([origin_hash, 2])
33+
origin_hash.should(eq({ 'a' => 1, 'b' => 2, 'c' => 3 }))
34+
end
35+
3036
end

0 commit comments

Comments
 (0)