diff --git a/lib/email.rb b/lib/email.rb index 06413f0f256..1b728aee7ea 100644 --- a/lib/email.rb +++ b/lib/email.rb @@ -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) diff --git a/spec/components/email/email_spec.rb b/spec/components/email/email_spec.rb index 4b278aa505c..95ac50c7970 100644 --- a/spec/components/email/email_spec.rb +++ b/spec/components/email/email_spec.rb @@ -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