|
16 | 16 | */ |
17 | 17 | var cookiejs = {}; |
18 | 18 |
|
19 | | - /** |
20 | | - * gets the current document.domain and returns .DOMAIN.TLD to make cookie accessable over all subdomains |
21 | | - * |
22 | | - * @private |
23 | | - * |
24 | | - * @returns {String} representation of ".DOMAIN.TLD" of document.domain |
25 | | - */ |
26 | | - var getCookieDomain = function() { |
27 | | - return '.' + document.domain.split('.').slice(-2).join('.'); |
28 | | - }; |
29 | | - |
30 | 19 | /** |
31 | 20 | * sets or overwrites a cookie |
32 | 21 | * |
|
39 | 28 | cookiejs.set = function(sCookieName, sValue, oAttributes) { |
40 | 29 | var sAttributes = ''; |
41 | 30 |
|
42 | | - oAttributes = oAttributes || { |
43 | | - domain: '; domain=' + getCookieDomain(), |
44 | | - path: '; path=/' |
45 | | - }; |
46 | | - |
47 | | - if (oAttributes['domain'] === undefined) { |
48 | | - sAttributes += '; domain=' + getCookieDomain(); |
49 | | - } |
| 31 | + oAttributes = oAttributes || {}; |
50 | 32 |
|
51 | | - if (oAttributes['path'] === undefined) { |
| 33 | + if (typeof oAttributes.path !== 'string') { |
52 | 34 | sAttributes += '; path=/'; |
53 | 35 | } |
54 | 36 |
|
55 | 37 | Object.keys(oAttributes).forEach(function(sAttributeName) { |
56 | 38 | sAttributes += ';' + sAttributeName + '=' + oAttributes[sAttributeName]; |
57 | | - }); |
| 39 | + }); |
58 | 40 |
|
59 | | - document.cookie = sCookieName + '=' + sValue + sAttributes; |
| 41 | + document.cookie = encodeURIComponent(sCookieName) + '=' + encodeURIComponent(sValue) + sAttributes; |
60 | 42 | }; |
61 | 43 |
|
62 | 44 | /** |
|
79 | 61 |
|
80 | 62 | for (var i = aCookies.length - 1; i >= 0; i--) { |
81 | 63 | aCookie = aCookies[i].split('='); |
82 | | - if (aCookie[0] === sCookieName) { |
83 | | - gCookieValue = aCookie[1]; |
| 64 | + if (decodeURIComponent(aCookie[0]) === sCookieName) { |
| 65 | + gCookieValue = decodeURIComponent(aCookie[1]); |
84 | 66 | } |
85 | 67 | } |
86 | 68 |
|
|
0 commit comments