Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F904895
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Aug 29, 4:51 PM
Size
1 KB
Mime Type
text/x-diff
Expires
Sun, Aug 31, 4:51 PM (1 d, 4 h)
Engine
blob
Format
Raw Data
Handle
252059
Attached To
rWEBDNS WebDNS (edet4)
View Options
diff --git a/lib/ipv4_validator.rb b/lib/ipv4_validator.rb
index 67e42ca..a619424 100644
--- a/lib/ipv4_validator.rb
+++ b/lib/ipv4_validator.rb
@@ -1,19 +1,20 @@
require 'ipaddr'
require 'socket'
class Ipv4Validator < ActiveModel::EachValidator
# Returns true if addr is a valid IPv4 address.
- def valid_v4?(addr)
+ def self.valid?(addr)
return false if addr['/'] # IPAddr accepts addr/mask format
IPAddr.new(addr, Socket::AF_INET)
true
rescue IPAddr::AddressFamilyError, IPAddr::InvalidAddressError
false
end
# Add an attribute error if this is not a valid IPv4 address.
def validate_each(record, attribute, value)
- return if valid_v4?(value)
+ return if Ipv4Validator.valid?(value)
+
record.errors[attribute] << 'is not a valid IPv4 address'
end
end
diff --git a/lib/ipv6_validator.rb b/lib/ipv6_validator.rb
index cdd1876..e6a67c6 100644
--- a/lib/ipv6_validator.rb
+++ b/lib/ipv6_validator.rb
@@ -1,22 +1,22 @@
require 'ipaddr'
require 'socket'
class Ipv6Validator < ActiveModel::EachValidator
# Returns true if addr is valid IPv6 address.
- def valid_v6?(addr)
+ def self.valid?(addr)
return false if addr['/'] # IPAddr accepts addr/mask format
return false if addr['[']
return false if addr[']']
IPAddr.new(addr, Socket::AF_INET6)
true
rescue IPAddr::AddressFamilyError, IPAddr::InvalidAddressError
false
end
# Add an attribute error if this is not a valid IPv4 address.
def validate_each(record, attribute, value)
- return if valid_v6?(value)
+ return if Ipv6Validator.valid?(value)
record.errors[attribute] << 'is not a valid IPv6 address'
end
end
Event Timeline
Log In to Comment