From cf9f7a6b7e4ede7edd612fde33f7149f9c7f3385 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Wed, 27 May 2015 20:05:01 +0100 Subject: validate_integer, validate_numeric: explicitely reject hashes in arrays Without this patch, Ruby 1.8's Hash#to_s behaviour causes [{1=>2}] to be treated as "12" when validating values. --- lib/puppet/parser/functions/validate_integer.rb | 1 + lib/puppet/parser/functions/validate_numeric.rb | 1 + 2 files changed, 2 insertions(+) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/functions/validate_integer.rb b/lib/puppet/parser/functions/validate_integer.rb index 995f8db..95da0c4 100644 --- a/lib/puppet/parser/functions/validate_integer.rb +++ b/lib/puppet/parser/functions/validate_integer.rb @@ -109,6 +109,7 @@ module Puppet::Parser::Functions # check every element of the array input.each_with_index do |arg, pos| begin + raise TypeError if arg.is_a?(Hash) arg = Integer(arg.to_s) validator.call(arg) rescue TypeError, ArgumentError diff --git a/lib/puppet/parser/functions/validate_numeric.rb b/lib/puppet/parser/functions/validate_numeric.rb index d2e4d16..3a14443 100644 --- a/lib/puppet/parser/functions/validate_numeric.rb +++ b/lib/puppet/parser/functions/validate_numeric.rb @@ -71,6 +71,7 @@ module Puppet::Parser::Functions # check every element of the array input.each_with_index do |arg, pos| begin + raise TypeError if arg.is_a?(Hash) arg = Float(arg.to_s) validator.call(arg) rescue TypeError, ArgumentError -- cgit v1.2.3