From 85d5eadbab273e838eb2de33e78054b8d3867f41 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Tue, 19 Nov 2013 20:24:46 -0800 Subject: [PATCH 1/2] Concatenate arrays without modifying the first array --- lib/puppet/parser/functions/concat.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/puppet/parser/functions/concat.rb b/lib/puppet/parser/functions/concat.rb index 6c8638222..0d35b07eb 100644 --- a/lib/puppet/parser/functions/concat.rb +++ b/lib/puppet/parser/functions/concat.rb @@ -28,11 +28,7 @@ module Puppet::Parser::Functions raise(Puppet::ParseError, 'concat(): Requires array to work with') end - if b.is_a?(Array) - result = a.concat(b) - else - result = a << b - end + result = a + Array(b) return result end From a6ad0af08e408adbb4b25684b18feb8aee12cf3e Mon Sep 17 00:00:00 2001 From: Spencer Krum Date: Tue, 19 Nov 2013 20:11:08 -0800 Subject: [PATCH 2/2] Introduce test for array destruction It was discovered that the concat array modifies the arrays passed to it as an argument as a side effect. This test will ensure that doesn't happen again. --- spec/functions/concat_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index b853b4c1a..49cb2ad7f 100755 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -27,4 +27,9 @@ expect(result).to(eq(['1','2','3',['4','5'],'6'])) end + it "should leave the original array intact" do + array_original = ['1','2','3'] + result = scope.function_concat([array_original,['4','5','6']]) + array_original.should(eq(['1','2','3'])) + end end