From 9a41f07e3b7f1ad44ac5260814867591f13a9d3e Mon Sep 17 00:00:00 2001 From: Will Farrington Date: Wed, 22 May 2013 17:19:03 -0700 Subject: Ruby 2.0 introduces IPAddr::InvalidAddressError --- lib/puppet/parser/functions/validate_ipv4_address.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions/validate_ipv4_address.rb') diff --git a/lib/puppet/parser/functions/validate_ipv4_address.rb b/lib/puppet/parser/functions/validate_ipv4_address.rb index 2de1454..fc02748 100644 --- a/lib/puppet/parser/functions/validate_ipv4_address.rb +++ b/lib/puppet/parser/functions/validate_ipv4_address.rb @@ -18,6 +18,13 @@ module Puppet::Parser::Functions ENDHEREDOC ) do |args| + require "ipaddr" + rescuable_exceptions = [ ArgumentError ] + + if defined?(IPAddr::InvalidAddressError) + rescuable_exceptions << IPAddr::InvalidAddressError + end + unless args.length > 0 then raise Puppet::ParseError, ("validate_ipv4_address(): wrong number of arguments (#{args.length}; must be > 0)") end @@ -31,7 +38,7 @@ module Puppet::Parser::Functions unless IPAddr.new(arg).ipv4? raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv4 address." end - rescue ArgumentError + rescue *rescuable_exceptions raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv4 address." end end -- cgit v1.2.3