From 07326d5a85d1df98dc57d759e8c13d019b77a70c Mon Sep 17 00:00:00 2001 From: Vratislav Bartonicek Date: Sun, 24 Dec 2023 12:23:12 -0800 Subject: [PATCH 1/2] Email regex update --- spec/src/utils/request-queue.js | 4 ++++ src/utils/helpers.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/src/utils/request-queue.js b/spec/src/utils/request-queue.js index 75a880fa..1494b50c 100644 --- a/spec/src/utils/request-queue.js +++ b/spec/src/utils/request-queue.js @@ -46,6 +46,10 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() { 'test@test.com.com', 'test+100@test.com', 'test-100@test-test.io', + ' test@test.io', + 'test@test.com.com ', + ' test.100@test.com.au ', + 'text test.100@test.io text', ], phone_number: [ '+12363334011', diff --git a/src/utils/helpers.js b/src/utils/helpers.js index c0540b50..e75fbbb8 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -5,7 +5,7 @@ const store = require('./store'); const purchaseEventStorageKey = '_constructorio_purchase_order_ids'; const PII_REGEX = { - email: /^[\w\-+\\.]+@([\w-]+\.)+[\w-]{2,4}$/, + email: /^.*\s[\w\-+\\.]+@([\w-]+\.)+[\w-]{2,4}\s.*$/, phoneNumber: /^(?:\+\d{11,12}|\+\d{1,3}\s\d{3}\s\d{3}\s\d{3,4}|\(\d{3}\)\d{7}|\(\d{3}\)\s\d{3}\s\d{4}|\(\d{3}\)\d{3}-\d{4}|\(\d{3}\)\s\d{3}-\d{4})$/, creditCard: /^(?:4[0-9]{15}|(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\d{3})\d{11})$/, // Visa, Mastercard, Amex, Discover, JCB and Diners Club, regex source: https://www.regular-expressions.info/creditcard.html From 1116db4ee245bbf4df59882618f2996082717dd8 Mon Sep 17 00:00:00 2001 From: Vratislav Bartonicek Date: Thu, 25 Jan 2024 14:27:20 -0800 Subject: [PATCH 2/2] PII - Update email regex and tests --- spec/src/utils/request-queue.js | 16 +++++++++++----- src/utils/helpers.js | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spec/src/utils/request-queue.js b/spec/src/utils/request-queue.js index 8d4e7296..6d03b27d 100644 --- a/spec/src/utils/request-queue.js +++ b/spec/src/utils/request-queue.js @@ -48,6 +48,11 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() { 'test@test.com.com', 'test+100@test.com', 'test-100@test-test.io', + ' test@test.io', + 'test@test.com.com ', + ' test.100@test.com.au ', + 'text test.100@test.io text', + 'test@test@test.com', // This string includes a valid email - test@test.com ], replaceBy: '', }, @@ -112,7 +117,6 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() { 'test123@.com.com', 'test()*@test.com', 'test@%*.com', - 'test@test@test.com', 'test@test', // Phone Number '123', @@ -234,8 +238,9 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() { expect(queue[index].url).to.equal(`https://ac.cnstrc.com/autocomplete/${replaceBy}/search?original_query=${replaceBy}&c=ciojs-2.686.3&i=c8a838d3-b7e0-48bd-92f1-81e08f84b9ee&s=5`); }); - expect(queue).to.be.an('array').length(43); - expect(store.local.get(storageKey)).to.be.an('array').length(43); + const piiCount = piiExamples.reduce((acc, curr) => acc + curr.queries.length, 0); + expect(queue).to.be.an('array').length(piiCount); + expect(store.local.get(storageKey)).to.be.an('array').length(piiCount); helpers.triggerUnload(); }); @@ -252,8 +257,9 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() { expect(queue[index].url).to.equal(`https://ac.cnstrc.com/autocomplete/${query}/search?original_query=${query}&c=ciojs-2.686.3&i=c8a838d3-b7e0-48bd-92f1-81e08f84b9ee&s=5`); }); - expect(RequestQueue.get()).to.be.an('array').length(36); - expect(store.local.get(storageKey)).to.be.an('array').length(36); + const noPiiCount = notPiiExamples.length; + expect(RequestQueue.get()).to.be.an('array').length(noPiiCount); + expect(store.local.get(storageKey)).to.be.an('array').length(noPiiCount); helpers.triggerUnload(); }); diff --git a/src/utils/helpers.js b/src/utils/helpers.js index d0c72991..bad06a5b 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -6,7 +6,7 @@ const purchaseEventStorageKey = '_constructorio_purchase_order_ids'; const PII_REGEX = [ { - pattern: /^[\w\-+\\.]+@([\w-]+\.)+[\w-]{2,4}$/, + pattern: /[\w\-+\\.]+@([\w-]+\.)+[\w-]{2,4}/, replaceBy: '', }, {