From 94c32ac7057f41bd205c1ca9dfcf479e5930e1a5 Mon Sep 17 00:00:00 2001 From: Ludovic Elice Date: Wed, 6 Oct 2021 09:23:55 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20Change=20testLinkedInUrlF?= =?UTF-8?q?ormat=20regex=20and=20add=20the=20test=20case?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/fieldValidators.js | 7 +++++++ src/fieldValidators.js | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/__tests__/fieldValidators.js b/src/__tests__/fieldValidators.js index d92f6ee..70bd31c 100644 --- a/src/__tests__/fieldValidators.js +++ b/src/__tests__/fieldValidators.js @@ -158,6 +158,10 @@ it('testEmailFormat', () => { }); describe('testLinkedInUrlFormat', () => { + it('Should return null if param url is null', () => { + const actual = testLinkedInUrlFormat(null); + expect(actual).toBe(null); + }); it('Should return notLinkedInUrl error message if param is not an url', () => { const actual = testLinkedInUrlFormat('Bob'); expect(actual).toBe('notLinkedInUrl'); @@ -180,6 +184,9 @@ describe('testLinkedInUrlFormat', () => { let actual = testLinkedInUrlFormat('https://www.linkedinsss.com/in/url-test/'); expect(actual).toBe('notLinkedInUrl'); + actual = testLinkedInUrlFormat('https://ww.linkedin.com/in/url-test/'); + expect(actual).toBe('notLinkedInUrl'); + actual = testLinkedInUrlFormat('https://wwwddd.linkedin.com/in/url-test/'); expect(actual).toBe('notLinkedInUrl'); diff --git a/src/fieldValidators.js b/src/fieldValidators.js index 29ddf7e..b8a3015 100644 --- a/src/fieldValidators.js +++ b/src/fieldValidators.js @@ -86,7 +86,7 @@ const testEmailFormat = (value: ?string) => { const testLinkedInUrlFormat = (value: ?string) => { if (!value) return null; - const regexp = /(https?):(\/\/)(([w]{3}||\w\w)\.)?linkedin.com\/in\/.+/; // eslint-disable-line no-control-regex + const regexp = /(https?):(\/\/)(www\.)?linkedin.com\/in\/.+/; // eslint-disable-line no-control-regex return regexp.test(value.trim()) ? null : 'notLinkedInUrl'; };