mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:19:27 +08:00
FIX: nil emails are invalid
This commit is contained in:
parent
02fa7448ca
commit
693b5234da
|
@ -7,6 +7,9 @@ require_dependency 'email/styles'
|
|||
module Email
|
||||
|
||||
def self.is_valid?(email)
|
||||
|
||||
return false unless String === email
|
||||
|
||||
parser = Mail::RFC2822Parser.new
|
||||
parser.root = :addr_spec
|
||||
result = parser.parse(email)
|
||||
|
|
|
@ -5,6 +5,10 @@ describe Email do
|
|||
|
||||
describe "is_valid?" do
|
||||
|
||||
it 'treats a nil as invalid' do
|
||||
expect(Email.is_valid?(nil)).to eq(false)
|
||||
end
|
||||
|
||||
it 'treats a good email as valid' do
|
||||
expect(Email.is_valid?('sam@sam.com')).to eq(true)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user