Skip to content

Commit 6c287b7

Browse files
ClearlyClairekmycode
authored andcommitted
Merge commit from fork
* Disallow some special characters in e-mail addresses * Add size limit to email columns
1 parent 5baf744 commit 6c287b7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class User < ApplicationRecord
9797

9898
has_one :custom_css, inverse_of: :user, dependent: :destroy
9999

100-
validates :email, presence: true, email_address: true
100+
validates :email, presence: true, email_address: true, length: { maximum: 320 }
101101

102102
validates_with UserEmailValidator, if: -> { ENV['EMAIL_DOMAIN_LISTS_APPLY_AFTER_CONFIRMATION'] == 'true' || !confirmed? }
103103
validates_with EmailMxValidator, if: :validate_email_dns?

app/validators/email_address_validator.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ def validate_each(record, attribute, value)
1111
value = value.strip
1212

1313
address = Mail::Address.new(value)
14-
record.errors.add(attribute, :invalid) if address.address != value
14+
record.errors.add(attribute, :invalid) if address.address != value || contains_disallowed_characters?(value)
1515
rescue Mail::Field::FieldError
1616
record.errors.add(attribute, :invalid)
1717
end
18+
19+
private
20+
21+
def contains_disallowed_characters?(value)
22+
value.include?('%') || value.include?(',') || value.include?('"')
23+
end
1824
end

0 commit comments

Comments
 (0)