From 7ad57680caaebc8cc8571a02d61cb10764d7b5ec Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Fri, 9 Oct 2015 14:30:08 -0700 Subject: [PATCH] fix(contacts): Emails only valid if the entire string is the email. (Sentry 2991) --- spec/stores/contact-store-spec.coffee | 17 +++++++++++++++++ src/flux/stores/contact-store.coffee | 6 +++++- src/flux/stores/draft-store.coffee | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/spec/stores/contact-store-spec.coffee b/spec/stores/contact-store-spec.coffee index 1090b9b63..674e6d2ee 100644 --- a/spec/stores/contact-store-spec.coffee +++ b/spec/stores/contact-store-spec.coffee @@ -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 '))).toBe(false) + expect(ContactStore.isValidContact(new Contact(name: 'Ben', email:''))).toBe(false) + expect(ContactStore.isValidContact(new Contact(name: 'Ben', email:'"ben@nylas.com"'))).toBe(false) + describe 'parseContactsInString', -> testCases = # Single contact test cases diff --git a/src/flux/stores/contact-store.coffee b/src/flux/stores/contact-store.coffee index 16b5ea64f..68c5d3196 100644 --- a/src/flux/stores/contact-store.coffee +++ b/src/flux/stores/contact-store.coffee @@ -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 diff --git a/src/flux/stores/draft-store.coffee b/src/flux/stores/draft-store.coffee index eaf8abf1e..e24048333 100644 --- a/src/flux/stores/draft-store.coffee +++ b/src/flux/stores/draft-store.coffee @@ -462,6 +462,7 @@ class DraftStore _onSendDraft: (draftClientId) => if atom.config.get("core.sending.sounds") SoundRegistry.playSound('hit-send') + @_draftsSending[draftClientId] = true @trigger(draftClientId)