lib/spf/model.rb in spf-0.0.18 vs lib/spf/model.rb in spf-0.0.19
- old
+ new
@@ -126,10 +126,12 @@
@ip_address = $1
elsif required
error(SPF::TermIPv4AddressExpectedError.new(
"Missing or invalid required IPv4 address in '#{@text}'"))
end
+ @ip_address = @parse_text.dup unless @ip_address
+
end
def parse_ipv4_prefix_length(required = false)
if @parse_text.sub!(/^\/(\d+)/, '')
bits = $1.to_i
@@ -149,20 +151,25 @@
end
def parse_ipv4_network(required = false)
self.parse_ipv4_address(required)
self.parse_ipv4_prefix_length
- @ip_network = IP.new("#{@ip_address}/#{@ipv4_prefix_length}") if @ip_address and @ipv4_prefix_length
+ begin
+ @ip_network = IP.new("#{@ip_address}/#{@ipv4_prefix_length}") if @ip_address and @ipv4_prefix_length
+ rescue ArgumentError
+ @ip_network = @ip_address
+ end
end
def parse_ipv6_address(required = false)
if @parse_text.sub!(/(#{IPV6_ADDRESS_PATTERN})(?=\/|$)/x, '')
@ip_address = $1
elsif required
error(SPF::TermIPv6AddressExpected.new(
"Missing required IPv6 address in '#{@text}'"))
end
+ @ip_address = @parse_text.dup unless @ip_address
end
def parse_ipv6_prefix_length(required = false)
if @parse_text.sub!(/^\/(\d+)/, '')
bits = $1.to_i
@@ -182,11 +189,15 @@
end
def parse_ipv6_network(required = false)
self.parse_ipv6_address(required)
self.parse_ipv6_prefix_length
- @ip_network = IP.new("#{@ip_address}/#{@ipv6_prefix_length}") if @ip_address and @ipv6_prefix_length
+ begin
+ @ip_network = IP.new("#{@ip_address}/#{@ipv6_prefix_length}") if @ip_address and @ipv6_prefix_length
+ rescue ArgumentError
+ @ip_network = @ip_address
+ end
end
def parse_ipv4_ipv6_prefix_lengths
self.parse_ipv4_prefix_length
if self.instance_variable_defined?(:@ipv4_prefix_length) and # An IPv4 prefix length has been parsed, and
@@ -427,15 +438,16 @@
NAME = 'ip4'
def parse_params(required = true)
self.parse_ipv4_network(required)
- @ip_netblocks << @ip_network
+ @ip_netblocks << @ip_network if IP === @ip_network
end
def params
return nil unless @ip_network
+ return @ip_network if String === @ip_network
result = @ip_network.to_addr
if @ip_network.pfxlen != @default_ipv4_prefix_length
result += "/#{@ip_network.pfxlen}"
end
return result
@@ -455,14 +467,15 @@
NAME = 'ip6'
def parse_params(required = true)
self.parse_ipv6_network(required)
- @ip_netblocks << @ip_network
+ @ip_netblocks << @ip_network if IP === @ip_network
end
def params
return nil unless @ip_network
+ result @ip_network if String === @ip_network
params = @ip_network.to_addr
params += '/' + @ip_network.pfxlen.to_s if
@ip_network.pfxlen != self.default_ipv6_prefix_length
return params
end