diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb index 4302b29e7..22eae3a44 100644 --- a/lib/puppet/parser/functions/upcase.rb +++ b/lib/puppet/parser/functions/upcase.rb @@ -13,22 +13,27 @@ module Puppet::Parser::Functions Will return: ASDF - EOS + EOS ) do |arguments| raise(Puppet::ParseError, "upcase(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 + "given (#{arguments.size} for 1)") if arguments.size < 1 value = arguments[0] - unless value.is_a?(Array) || value.is_a?(String) - raise(Puppet::ParseError, 'upcase(): Requires either ' + - 'array or string to work with') + unless value.is_a?(Array) || value.is_a?(String) || value.is_a?(Hash) + raise(Puppet::ParseError, 'upcase(): Requires an ' + + 'array, string or hash to work with') end if value.is_a?(Array) # Numbers in Puppet are often string-encoded which is troublesome ... result = value.collect { |i| i.is_a?(String) ? i.upcase : i } + elsif value.is_a?(Hash) + result = {} + result << value.each_pair do |k, v| + return {k.upcase => v.collect! { |p| p.upcase }} + end else result = value.upcase end diff --git a/spec/functions/upcase_spec.rb b/spec/functions/upcase_spec.rb index 3cf8b0552..a50a3ab3a 100755 --- a/spec/functions/upcase_spec.rb +++ b/spec/functions/upcase_spec.rb @@ -9,7 +9,7 @@ end it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_upcase([]) }.to( raise_error(Puppet::ParseError)) + expect { scope.function_upcase([]) }.to(raise_error(Puppet::ParseError)) end it "should upcase a string" do @@ -30,4 +30,10 @@ class AlsoString < String result = scope.function_upcase([value]) result.should(eq('ABC')) end + + it 'should accept hashes and return uppercase' do + expect( + scope.function_upcase([{'test' => %w(this that and other thing)}]) + ).to eq({'TEST' => %w(THIS THAT AND OTHER THING)}) + end end