fix(contacts): Emails only valid if the entire string is the email. (Sentry 2991)

This commit is contained in:
Ben Gotow 2015-10-09 14:30:08 -07:00
parent a84787859c
commit 7ad57680ca
3 changed files with 23 additions and 1 deletions

View file

@ -127,6 +127,23 @@ describe "ContactStore", ->
results = ContactStore.searchContacts("fi", limit: 6, noPromise: true)
expect(results.length).toBe 6
describe 'isValidContact', ->
it "should return true for a variety of valid contacts", ->
expect(ContactStore.isValidContact(new Contact(name: 'Ben', email: 'ben@nylas.com'))).toBe(true)
expect(ContactStore.isValidContact(new Contact(email: 'ben@nylas.com'))).toBe(true)
expect(ContactStore.isValidContact(new Contact(email: 'ben+123@nylas.com'))).toBe(true)
it "should return false for non-Contact objects", ->
expect(ContactStore.isValidContact({name: 'Ben', email: 'ben@nylas.com'})).toBe(false)
it "should return false if the contact has no email", ->
expect(ContactStore.isValidContact(new Contact(name: 'Ben'))).toBe(false)
it "should return false if the contact has an email that is not valid", ->
expect(ContactStore.isValidContact(new Contact(name: 'Ben', email:'Ben <ben@nylas.com>'))).toBe(false)
expect(ContactStore.isValidContact(new Contact(name: 'Ben', email:'<ben@nylas.com>'))).toBe(false)
expect(ContactStore.isValidContact(new Contact(name: 'Ben', email:'"ben@nylas.com"'))).toBe(false)
describe 'parseContactsInString', ->
testCases =
# Single contact test cases

View file

@ -113,7 +113,11 @@ class ContactStore extends NylasStore
#
isValidContact: (contact) =>
return false unless contact instanceof Contact
return contact.email and RegExpUtils.emailRegex().test(contact.email)
return false unless contact.email
# The email regexp must match the /entire/ email address
[match] = RegExpUtils.emailRegex().exec(contact.email)
return match is contact.email
parseContactsInString: (contactString, options={}) =>
{skipNameLookup} = options

View file

@ -462,6 +462,7 @@ class DraftStore
_onSendDraft: (draftClientId) =>
if atom.config.get("core.sending.sounds")
SoundRegistry.playSound('hit-send')
@_draftsSending[draftClientId] = true
@trigger(draftClientId)