diff --git a/src/helpers/cookie-utils.js b/src/helpers/cookie-utils.js index 1fc61fed..447d6f07 100644 --- a/src/helpers/cookie-utils.js +++ b/src/helpers/cookie-utils.js @@ -59,22 +59,23 @@ export const parseCookieString = (cookieString) => { const COOKIE_DELIMITER = '='; const COOKIE_PAIRS_DELIMITER = ';'; - return cookieString - .split(COOKIE_PAIRS_DELIMITER) - .reduce((result, string) => { - const delimiterIndex = string.indexOf(COOKIE_DELIMITER); - let cookieKey; - let cookieValue; - if (delimiterIndex === -1) { - cookieKey = string.trim(); - } else { - cookieKey = string.slice(0, delimiterIndex).trim(); - cookieValue = string.slice(delimiterIndex + 1); - } + // Get raw cookies + const cookieChunks = cookieString.split(COOKIE_PAIRS_DELIMITER); + const cookieData = {}; - return Object.defineProperty(result, cookieKey, { - value: cookieValue || null, - enumerable: true, - }); - }, {}); + cookieChunks.forEach((singleCookie) => { + let cookieKey; + let cookieValue; + const delimiterIndex = singleCookie.indexOf(COOKIE_DELIMITER); + if (delimiterIndex === -1) { + cookieKey = singleCookie.trim(); + } else { + cookieKey = singleCookie.slice(0, delimiterIndex).trim(); + cookieValue = singleCookie.slice(delimiterIndex + 1); + } + // Save cookie key=value data with null instead of empty ('') values + cookieData[cookieKey] = cookieValue || null; + }); + + return cookieData; };