Skip to content

Commit dad3a29

Browse files
committed
Merge pull request #147 from mhellmic/master
don't fail on undef variable in merge
2 parents 1ffd72d + b975bd6 commit dad3a29

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/puppet/parser/functions/merge.rb

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module Puppet::Parser::Functions
2222
accumulator = Hash.new
2323
# Merge into the accumulator hash
2424
args.each do |arg|
25+
next if arg.is_a? String and arg.empty? # empty string is synonym for puppet's undef
2526
unless arg.is_a?(Hash)
2627
raise Puppet::ParseError, "merge: unexpected argument type #{arg.class}, only expects hash arguments"
2728
end

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

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
describe 'when calling merge on the scope instance' do
2727
it 'should require all parameters are hashes' do
2828
expect { new_hash = scope.function_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/)
29+
expect { new_hash = scope.function_merge([{}, 2])}.to raise_error(Puppet::ParseError, /unexpected argument type Fixnum/)
30+
end
31+
32+
it 'should accept empty strings as puppet undef' do
33+
expect { new_hash = scope.function_merge([{}, ''])}.not_to raise_error(Puppet::ParseError, /unexpected argument type String/)
2934
end
3035

3136
it 'should be able to merge two hashes' do

0 commit comments

Comments
 (0)