Skip to content

Commit 2841fd8

Browse files
committed
minor review
1 parent c5169e1 commit 2841fd8

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

‎jquery.cookie.js‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$.cookie = function(key, value, options) {
1212

1313
// key and at least value given, set cookie...
14-
if (arguments.length > 1 && (Object.prototype.toString.call(value) === "[object String]" || value === null || value === undefined)) {
14+
if (arguments.length > 1 && (Object.prototype.toString.call(value) === '[object String]' || value === null || value === undefined)) {
1515
options = $.extend({}, options);
1616

1717
if (value === null || value === undefined) {
@@ -26,23 +26,21 @@
2626
value = String(value);
2727

2828
return (document.cookie = [
29-
encodeURIComponent(key), '=',
30-
options.raw ? value : encodeURIComponent(value),
29+
encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
3130
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
32-
options.path ? '; path=' + options.path : '',
33-
options.domain ? '; domain=' + options.domain : '',
34-
options.secure ? '; secure' : ''
31+
options.path ? '; path=' + options.path : '',
32+
options.domain ? '; domain=' + options.domain : '',
33+
options.secure ? '; secure' : ''
3534
].join(''));
3635
}
3736

3837
// key and possibly options given, get cookie...
3938
options = value || {};
4039
var decode = options.raw ? function(s) { return s; } : decodeURIComponent;
4140

42-
var parts = document.cookie.split('; ');
43-
for (var i = 0, part; part = parts[i]; i++) {
44-
var pair = part.split('=');
45-
if (decode(pair[0]) === key) return decode(pair[1] || ''); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB
41+
var pairs = document.cookie.split('; ');
42+
for (var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
43+
if (decode(pair[0]) === key) return decode(pair[1] || ''); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, thus pair[1] may be undefined
4644
}
4745
return null;
4846
};

0 commit comments

Comments
 (0)