mirror of
https://github.com/mastodon/mastodon.git
synced 2026-05-09 04:22:42 -05:00
Merge commit from fork
* Disallow some special characters in e-mail addresses * Add size limit to email columns
This commit is contained in:
parent
081debc971
commit
5e43c8db56
|
|
@ -99,7 +99,7 @@ class User < ApplicationRecord
|
|||
accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? && !Setting.require_invite_text }
|
||||
validates :invite_request, presence: true, on: :create, if: :invite_text_required?
|
||||
|
||||
validates :email, presence: true, email_address: true
|
||||
validates :email, presence: true, email_address: true, length: { maximum: 320 }
|
||||
|
||||
validates_with UserEmailValidator, if: -> { ENV['EMAIL_DOMAIN_LISTS_APPLY_AFTER_CONFIRMATION'] == 'true' || !confirmed? }
|
||||
validates_with EmailMxValidator, if: :validate_email_dns?
|
||||
|
|
|
|||
|
|
@ -11,8 +11,14 @@ class EmailAddressValidator < ActiveModel::EachValidator
|
|||
value = value.strip
|
||||
|
||||
address = Mail::Address.new(value)
|
||||
record.errors.add(attribute, :invalid) if address.address != 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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user