From 83510d0ceff63b173a39a044d75bdb6e06700f31 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Fri, 13 Nov 2015 11:42:30 -0800 Subject: [PATCH] fix(names): "Olivia" should not be caught by name cleanup This fixes #393. The name "Olivia" was being caught in our parser designed to shorten "Mike Kaylor via LinkedIn" to "Mike Kaylor". We now check that "via" is it's own distinct word in the phrase. --- spec/models/contact-spec.coffee | 9 +++++++++ src/flux/models/contact.coffee | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/spec/models/contact-spec.coffee b/spec/models/contact-spec.coffee index 59419d78f..8d48dfe2b 100644 --- a/spec/models/contact-spec.coffee +++ b/spec/models/contact-spec.coffee @@ -54,6 +54,15 @@ describe "Contact", -> c8 = new Contact {name: "Mike Kaylor via LinkedIn"} expect(c8.firstName()).toBe "Mike" expect(c8.lastName()).toBe "Kaylor" + c8 = new Contact {name: "Mike Kaylor VIA LinkedIn"} + expect(c8.firstName()).toBe "Mike" + expect(c8.lastName()).toBe "Kaylor" + c8 = new Contact {name: "Mike Viator"} + expect(c8.firstName()).toBe "Mike" + expect(c8.lastName()).toBe "Viator" + c8 = new Contact {name: "Olivia Pope"} + expect(c8.firstName()).toBe "Olivia" + expect(c8.lastName()).toBe "Pope" it "properly parses evan (Evan Morikawa)", -> c8 = new Contact {name: "evan (Evan Morikawa)"} diff --git a/src/flux/models/contact.coffee b/src/flux/models/contact.coffee index b85c42256..93b2f8b31 100644 --- a/src/flux/models/contact.coffee +++ b/src/flux/models/contact.coffee @@ -122,8 +122,8 @@ class Contact extends Model name = name.split(/[()]/)[1] if name.split(/[()]/).length > 1 # Take care of phrases like "Mike Kaylor via LinkedIn" that should be displayed - # as the contents before the separator word. - name = name.split(/(via)/)[0] + # as the contents before the separator word. Do not break "Olivia" + name = name.split(/(\svia\s)/i)[0] # If the phrase has an '@', use everything before the @ sign # Unless that would result in an empty string!