Skip to content

Commit

Permalink
More cookie handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveWang committed Aug 7, 2011
1 parent daf7f92 commit fc9948c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/nowUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,32 @@ var util = {
if (typeof cookie !== 'string') {
return {};
}
var regex = /([^=\s]+)=(.*?)(;|$|\s)/g;
var regex = /(.+?)(;|$)\s*/g;
var match = cookie.match(regex);
if (!match) {
return {};
}
var jsonCookie = {};
var index;
var m;
for (var i = 0; i < match.length; i++) {
m = match[i];
index = match[i].indexOf('=');
jsonCookie[match[i].substring(0, index)] = match[i].substring(index + 1, match[i].length - (1 + match[i].indexOf(';') ? 1: 0));

if (index === -1) {
jsonCookie[m.substr(index + 1,
m.lastIndexOf(';') + 1 ?
m.lastIndexOf(';') - index - 1:
undefined)] = true;
} else {
console.log(m);
console.log(m.lastIndexOf(';'));
console.log(m.substr(0, m.lastIndexOf(';')));
jsonCookie[m.substr(0, index)] = m.substr(index + 1,
(m.lastIndexOf(';') + 1 ?
m.lastIndexOf(';') - index - 1 :
undefined));
}
}
return jsonCookie;
},
Expand Down

0 comments on commit fc9948c

Please sign in to comment.