diff --git a/spec/stores/contact-store-spec.coffee b/spec/stores/contact-store-spec.coffee index c4d25b7b9..f1e1112b2 100644 --- a/spec/stores/contact-store-spec.coffee +++ b/spec/stores/contact-store-spec.coffee @@ -139,6 +139,18 @@ describe "ContactStore", -> expect(ContactStore.isValidContact(new Contact(name: 'Ben', email:''))).toBe(false) expect(ContactStore.isValidContact(new Contact(name: 'Ben', email:'"ben@nylas.com"'))).toBe(false) + it "returns false if we're not passed a contact", -> + expect(ContactStore.isValidContact()).toBe false + + it "returns false if the contact doesn't have an email", -> + expect(ContactStore.isValidContact(new Contact(name: "test"))).toBe false + + it "returns false if the email doesn't satisfy the regex", -> + expect(ContactStore.isValidContact(new Contact(name: "test", email: "foo"))).toBe false + + it "returns false if the email doesn't match", -> + expect(ContactStore.isValidContact(new Contact(name: "test", email: "foo@"))).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 68c5d3196..3c70045f2 100644 --- a/src/flux/stores/contact-store.coffee +++ b/src/flux/stores/contact-store.coffee @@ -116,8 +116,10 @@ class ContactStore extends NylasStore 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 + result = RegExpUtils.emailRegex().exec(contact.email) + if result and result instanceof Array + return result[0] is contact.email + else return false parseContactsInString: (contactString, options={}) => {skipNameLookup} = options