Skip to content

Commit 5cc5e29

Browse files
committed
Merge pull request #178 from lmello/fix_bug_20681
bug # 20681 delete() function should not remove elements from original list
2 parents ebec9de + c14cbf3 commit 5cc5e29

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/puppet/parser/functions/delete.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Puppet::Parser::Functions
2727
"given #{arguments.size} for 2.")
2828
end
2929

30-
collection = arguments[0]
30+
collection = arguments[0].dup
3131
item = arguments[1]
3232

3333
case collection

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,22 @@
3535
result.should(eq({ 'a' => 1, 'c' => 3 }))
3636
end
3737

38+
it "should not change origin array passed as argument" do
39+
origin_array = ['a','b','c','d']
40+
result = scope.function_delete([origin_array, 'b'])
41+
origin_array.should(eq(['a','b','c','d']))
42+
end
43+
44+
it "should not change the origin string passed as argument" do
45+
origin_string = 'foobarbabarz'
46+
result = scope.function_delete([origin_string,'bar'])
47+
origin_string.should(eq('foobarbabarz'))
48+
end
49+
50+
it "should not change origin hash passed as argument" do
51+
origin_hash = { 'a' => 1, 'b' => 2, 'c' => 3 }
52+
result = scope.function_delete([origin_hash, 'b'])
53+
origin_hash.should(eq({ 'a' => 1, 'b' => 2, 'c' => 3 }))
54+
end
55+
3856
end

0 commit comments

Comments
 (0)