Skip to content

Commit d183a24

Browse files
authored
Merge pull request #1654 from algolia/fix/MAGE-1101-getcookie-3.14.4
MAGE-1101: change getCookie method (3.14.4)
2 parents f5a88e4 + de626ce commit d183a24

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

view/frontend/web/js/internals/common.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
define(['jquery', 'algoliaBundle'], function ($, algoliaBundle) {
1+
define(
2+
['jquery', 'algoliaBundle', 'Magento_PageCache/js/form-key-provider',], function ($, algoliaBundle, formKeyInit) {
23
// Character maps supplied for more performant Regex ops
34
const SPECIAL_CHAR_ENCODE_MAP = {
45
'&': '&',
@@ -98,15 +99,26 @@ define(['jquery', 'algoliaBundle'], function ($, algoliaBundle) {
9899
return check;
99100
};
100101

101-
window.getCookie = function (name) {
102-
var value = "; " + document.cookie;
103-
var parts = value.split("; " + name + "=");
104-
if (parts.length == 2) {
105-
return parts.pop().split(";").shift();
102+
window.getCookie = function(name) {
103+
let cookie, i;
104+
105+
const cookieName = name + "=",
106+
cookieArr = document.cookie.split(';');
107+
108+
for (i = 0; i < cookieArr.length; i++) {
109+
cookie = cookieArr[i];
110+
111+
while (cookie.charAt(0) === ' ') {
112+
cookie = cookie.substring(1, cookie.length);
113+
}
114+
115+
if (cookie.indexOf(cookieName) === 0) {
116+
return cookie.substring(cookieName.length, cookie.length);
117+
}
106118
}
107119

108120
return "";
109-
};
121+
}
110122

111123
window.transformHit = function (hit, price_key, helper) {
112124
if (Array.isArray(hit.categories))

0 commit comments

Comments
 (0)