fix(contact): fix bug where malformed contacts threw an error

Summary:
Also added tests to catch the case
Fixes T4290

Test Plan: new tests

Reviewers: bengotow

Reviewed By: bengotow

Maniphest Tasks: T4290

Differential Revision: https://phab.nylas.com/D2153
This commit is contained in:
Evan Morikawa 2015-10-12 14:03:39 -04:00
parent abe0e1baac
commit 78a3218c26
2 changed files with 16 additions and 2 deletions

View file

@ -139,6 +139,18 @@ describe "ContactStore", ->
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)
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)
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', -> describe 'parseContactsInString', ->
testCases = testCases =
# Single contact test cases # Single contact test cases

View file

@ -116,8 +116,10 @@ class ContactStore extends NylasStore
return false unless contact.email return false unless contact.email
# The email regexp must match the /entire/ email address # The email regexp must match the /entire/ email address
[match] = RegExpUtils.emailRegex().exec(contact.email) result = RegExpUtils.emailRegex().exec(contact.email)
return match is contact.email if result and result instanceof Array
return result[0] is contact.email
else return false
parseContactsInString: (contactString, options={}) => parseContactsInString: (contactString, options={}) =>
{skipNameLookup} = options {skipNameLookup} = options