From b28f03d76c34d71cea2601424f8cc8754292b0a5 Mon Sep 17 00:00:00 2001 From: FrankRua Date: Thu, 14 Apr 2022 11:46:17 -0400 Subject: [PATCH 1/2] Cookie sometimes contains more than one value --- .../heritage-integration/cookie-helper.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/helpers/heritage-integration/cookie-helper.js b/src/helpers/heritage-integration/cookie-helper.js index 5a9ed4691..2dd8006fb 100644 --- a/src/helpers/heritage-integration/cookie-helper.js +++ b/src/helpers/heritage-integration/cookie-helper.js @@ -57,9 +57,16 @@ export function getCookieDomainValue() { Returns empty string if cookie not found or "did" string not present. */ export function getDeviceIdValue(){ - const cookieValue = getCookieByName(cookieNames.DXDEV); - const cookieValueMatch = cookieValue.match("(?<=did=).*?(?=&)"); + // Sometimes these cookie contains more than the device ID. + const cookieValue = getCookieValueByName(cookieNames.DXDEV); + const cookieValuesSplit = cookieValue.split('='); + // If this is the only value, just use that. + if(cookieValuesSplit.length === 2){ + return cookieValuesSplit[1]; + } + + const cookieValueMatch = cookieValue.match("(?<=did=).*?(?=&)"); if(cookieValueMatch){ return cookieValueMatch[0]; } @@ -71,7 +78,7 @@ export function getDeviceIdValue(){ Gets value of sid cookie, returns empty string if not found. */ export function getSessionIdValue(){ - const cookieValue = getCookieByName(cookieNames.SESSION_ID); + const cookieValue = getCookieValueByName(cookieNames.SESSION_ID); if(cookieValue){ return cookieValue; @@ -84,7 +91,7 @@ export function getSessionIdValue(){ Gets value of skey cookie, returns 0 if not found. */ export function getSessionKeyValue(){ - const cookieValue = getCookieByName(cookieNames.SESSION_KEY); + const cookieValue = getCookieValueByName(cookieNames.SESSION_KEY); if(cookieValue){ return cookieValue; @@ -140,7 +147,7 @@ function getDomainWithoutSubdomain() { /* Gets cookie value by name, returns empty string if not found. */ -function getCookieByName(name) { +function getCookieValueByName(name) { const value = "; " + document.cookie; const parts = value.split("; " + name + "="); From d13f2ec9e58eeaa42a42702e6e500aae3ca43d4b Mon Sep 17 00:00:00 2001 From: FrankRua Date: Thu, 14 Apr 2022 11:48:35 -0400 Subject: [PATCH 2/2] one more bit of logic --- src/helpers/heritage-integration/cookie-helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/heritage-integration/cookie-helper.js b/src/helpers/heritage-integration/cookie-helper.js index 2dd8006fb..52cb17642 100644 --- a/src/helpers/heritage-integration/cookie-helper.js +++ b/src/helpers/heritage-integration/cookie-helper.js @@ -62,7 +62,7 @@ export function getDeviceIdValue(){ const cookieValuesSplit = cookieValue.split('='); // If this is the only value, just use that. - if(cookieValuesSplit.length === 2){ + if(cookieValuesSplit.length === 2 && cookieValuesSplit[0] === 'did'){ return cookieValuesSplit[1]; }