mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 02:40:53 -06:00
FIX: strip whitespaces from user email
This commit is contained in:
parent
22adb682d8
commit
6c410ed093
@ -62,7 +62,7 @@ class User < ActiveRecord::Base
|
||||
|
||||
delegate :last_sent_email_address, :to => :email_logs
|
||||
|
||||
before_validation :downcase_email
|
||||
before_validation :strip_downcase_email
|
||||
|
||||
validates_presence_of :username
|
||||
validate :username_validator
|
||||
@ -764,8 +764,11 @@ class User < ActiveRecord::Base
|
||||
self.username_lower = username.downcase
|
||||
end
|
||||
|
||||
def downcase_email
|
||||
self.email = self.email.downcase if self.email
|
||||
def strip_downcase_email
|
||||
if self.email
|
||||
self.email = self.email.strip
|
||||
self.email = self.email.downcase
|
||||
end
|
||||
end
|
||||
|
||||
def username_validator
|
||||
|
@ -261,8 +261,14 @@ describe User do
|
||||
|
||||
it "downcases email addresses" do
|
||||
user = Fabricate.build(:user, email: 'Fancy.Caps.4.U@gmail.com')
|
||||
user.save
|
||||
expect(user.reload.email).to eq('fancy.caps.4.u@gmail.com')
|
||||
user.valid?
|
||||
expect(user.email).to eq('fancy.caps.4.u@gmail.com')
|
||||
end
|
||||
|
||||
it "strips whitespace from email addresses" do
|
||||
user = Fabricate.build(:user, email: ' example@gmail.com ')
|
||||
user.valid?
|
||||
expect(user.email).to eq('example@gmail.com')
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user