(maint) clean up validate_slength argument validation

This commit is contained in:
Adrien Thebo 2013-08-12 11:27:56 -07:00
parent e63715ddaf
commit 6df05cbc2d

View file

@ -30,24 +30,26 @@ module Puppet::Parser::Functions
end end
begin begin
max_length = max_length.to_i max_length = Integer(max_length)
rescue NoMethodError => e raise ArgumentError if max_length <= 0
raise Puppet::ParseError, "validate_slength(): Expected second argument to be a positive Numeric, got a #{max_length.class}" rescue ArgumentError, TypeError
raise Puppet::ParseError, "validate_slength(): Expected second argument to be a positive Numeric, got #{max_length}:#{max_length.class}"
end end
unless args.length == 2 if min_length
begin begin
min_length = Integer(min_length) min_length = Integer(min_length)
rescue StandardError => e raise ArgumentError if min_length < 0
raise Puppet::ParseError, "validate_slength(): Expected third argument to be unset or a positive Numeric, got a #{min_length.class}" rescue ArgumentError, TypeError
raise Puppet::ParseError, "validate_slength(): Expected third argument to be unset or a positive Numeric, got #{min_length}:#{min_length.class}"
end end
else else
min_length = 0 min_length = 0
end end
raise Puppet::ParseError, "validate_slength(): please pass a positive number as max_length" unless max_length > 0 if min_length > max_length
raise Puppet::ParseError, "validate_slength(): please pass a positive number as min_length" unless min_length >= 0 raise Puppet::ParseError, "validate_slength(): Expected second argument to be larger than third argument"
raise Puppet::ParseError, "validate_slength(): please pass a min length that is smaller than the maximum" unless min_length <= max_length end
case input case input
when String when String