mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
Fixes for postgresql inet columns in Rails 4. They're backed by an IPAddr class now, which breaks sql parameter marker support, and automatically sets the attribute to nil when trying to assign an invalid ip address.
This commit is contained in:
@ -3,8 +3,16 @@
|
||||
class IpAddressFormatValidator < ActiveModel::EachValidator
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
unless record.ip_address.nil? or record.ip_address.split('/').first =~ Resolv::AddressRegex
|
||||
record.errors.add(attribute, :invalid)
|
||||
if rails4?
|
||||
# In Rails 4, ip_address will be nil if an invalid IP address was assigned.
|
||||
# https://github.com/jetthoughts/rails/commit/0aa95a71b04f2893921c58a7c1d9fca60dbdcbc2
|
||||
if record.ip_address.nil?
|
||||
record.errors.add(attribute, :invalid)
|
||||
end
|
||||
else
|
||||
unless !record.ip_address.nil? and record.ip_address.to_s.split('/').first =~ Resolv::AddressRegex
|
||||
record.errors.add(attribute, :invalid)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user