Skip to content

Commit e3a6e2c

Browse files
committed
Merge pull request #590 from alext/fix_concat_with_hash
(MODULES-3246) Fix concat with Hash arguments.
2 parents 60864fd + 44596e7 commit e3a6e2c

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/puppet/parser/functions/concat.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module Puppet::Parser::Functions
3131
arguments.shift
3232

3333
arguments.each do |x|
34-
result = result + Array(x)
34+
result = result + (x.is_a?(Array) ? x : [x])
3535
end
3636

3737
return result

spec/acceptance/concat_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@
3434
}
3535
EOS
3636

37+
apply_manifest(pp, :catch_failures => true)
38+
end
39+
it 'should concat hash arguments' do
40+
pp = <<-EOS
41+
$output = concat([{"a" => "b"}], {"c" => "d", "e" => "f"})
42+
validate_array($output)
43+
if size($output) != 2 {
44+
fail("${output} should have 2 elements.")
45+
}
46+
if $output[1] != {"c" => "d", "e" => "f"} {
47+
fail("${output} does not have the expected hash for the second element.")
48+
}
49+
EOS
50+
3751
apply_manifest(pp, :catch_failures => true)
3852
end
3953
end

spec/functions/concat_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
it { is_expected.to run.with_params(['1','2','3'],[['4','5'],'6']).and_return(['1','2','3',['4','5'],'6']) }
1212
it { is_expected.to run.with_params(['1','2'],['3','4'],['5','6']).and_return(['1','2','3','4','5','6']) }
1313
it { is_expected.to run.with_params(['1','2'],'3','4',['5','6']).and_return(['1','2','3','4','5','6']) }
14+
it { is_expected.to run.with_params([{"a" => "b"}], {"c" => "d", "e" => "f"}).and_return([{"a" => "b"}, {"c" => "d", "e" => "f"}]) }
1415

1516
it "should leave the original array intact" do
1617
argument1 = ['1','2','3']

0 commit comments

Comments
 (0)