mirror of
https://github.com/mastodon/mastodon.git
synced 2026-06-10 09:37:24 -05:00
19 lines
530 B
Ruby
19 lines
530 B
Ruby
# frozen_string_literal: true
|
|
|
|
class EmailAddressValidator < ActiveModel::EachValidator
|
|
def validate_each(record, attribute, value)
|
|
value = value.strip
|
|
|
|
address = Mail::Address.new(value)
|
|
record.errors.add(attribute, :invalid) if address.address != value || contains_disallowed_characters?(value)
|
|
rescue Mail::Field::FieldError
|
|
record.errors.add(attribute, :invalid)
|
|
end
|
|
|
|
private
|
|
|
|
def contains_disallowed_characters?(value)
|
|
value.include?('%') || value.include?(',') || value.include?('"')
|
|
end
|
|
end
|