FEATURE: screened IP address range can be entered like 192.* instead of 192.*.*.*
This commit is contained in:
parent
b1567488b7
commit
d96acdeafa
|
@ -29,12 +29,15 @@ class ScreenedIpAddress < ActiveRecord::Base
|
|||
if num_wildcards == 0
|
||||
write_attribute(:ip_address, val)
|
||||
else
|
||||
v = val.gsub(/\/.*/, '')
|
||||
v = val.gsub(/\/.*/, '') # strip ranges like "/16" from the end if present
|
||||
if v[v.index('*')..-1] =~ /[^\.\*]/
|
||||
self.errors.add(:ip_address, :invalid)
|
||||
return
|
||||
end
|
||||
write_attribute(:ip_address, "#{v.gsub('*', '0')}/#{32 - (num_wildcards * 8)}")
|
||||
parts = v.split('.')
|
||||
(4 - parts.size).times { parts << '*' } # support strings like 192.*
|
||||
v = parts.join('.')
|
||||
write_attribute(:ip_address, "#{v.gsub('*', '0')}/#{32 - (v.count('*') * 8)}")
|
||||
end
|
||||
|
||||
# this gets even messier, Ruby 1.9.2 raised a different exception to Ruby 2.0.0
|
||||
|
|
|
@ -76,6 +76,8 @@ describe ScreenedIpAddress do
|
|||
test_good_value("123.12.*.*", "123.12.0.0/16")
|
||||
test_good_value("123.12.1.*", "123.12.1.0/24")
|
||||
test_good_value("123.12.*.*/16", "123.12.0.0/16")
|
||||
test_good_value("123.12.*", "123.12.0.0/16")
|
||||
test_good_value("123.*", "123.0.0.0/8")
|
||||
end
|
||||
|
||||
it "handles bad input" do
|
||||
|
|
Loading…
Reference in New Issue