var COOKIE_PAIR = /^([^=\s]+)\s*=\s*("?)\s*(.*)\s*\2\s*$/,
    TRAILING_SEMICOLON = /;+$/,
    KEY_INDEX = 1,
    VALUE_INDEX = 3;

function remove_trailing_semicolon(str) {
  var regexp_match = TRAILING_SEMICOLON.exec(str);
  return regexp_match ? str.slice(0, regexp_match.index) : str;
}

function get_first_pair(str) {
  return str.split(/\s*;\s*/).shift();
}

function parse(str, decode) {
  decode = decode || decodeURIComponent;

  str = str.trim();
  str = remove_trailing_semicolon(str);
  str = get_first_pair(str);

  var res = COOKIE_PAIR.exec(str);
  return {
    key: decode(res[KEY_INDEX]),
    value: decode(res[VALUE_INDEX])
  };
}

// returns a key/val object from an array of cookie strings
exports.read = function (header, decode) {
  var res = {};
  header = (header instanceof Array) ? header : [header];

  header.forEach(function (cookie_str) {
    var cookie = parse(cookie_str, decode);
    res[cookie.key] = cookie.value;
  });

  return res;
};

// writes a cookie string header
exports.write = function(obj, encode) {
  encode = encode || encodeURIComponent;

  return Object.keys(obj).map(function(key) {
    return encode(key) + '=' + encode(obj[key]);
  }).join('; ');
};

@@ -80,24 +80,63 @@
 ON = /;+$/,%0A
+    EXCLUDED_CHARS = /%5B%5C%22%5C%5C;%5Cs%5C%22%5C,%5D/g,%0A
     KEY_INDE
@@ -410,70 +410,120 @@
 ion 
-parse(str, decode) %7B%0A  decode = decode %7C%7C decodeURIComponent;%0A
+encodeCookieComponent(str) %7B%0A  return str.replace(EXCLUDED_CHARS, encodeURIComponents);%0A%7D%0A%0Afunction parse(str) %7B
 %0A  s
@@ -666,24 +666,36 @@
  key: decode
+URIComponent
 (res%5BKEY_IND
@@ -717,16 +717,28 @@
 : decode
+URIComponent
 (res%5BVAL
@@ -1142,31 +1142,85 @@
 ion(
-obj, encode) %7B%0A 
+cookies) %7B%0Areturn Object.keys(cookies).map(function(key) %7B%0A    var
  encode
+dKey
  = e
@@ -1228,21 +1228,14 @@
 code
- %7C%7C%C2%A0encodeURI
+Cookie
 Comp
@@ -1243,56 +1243,74 @@
 nent
+(key)
 ;%0A
-%0A  return Object.keys(obj).map(function(key) %7B
+    var encodedValue = encodeCookieComponent(cookies%5Bkey%5D);
 %0A   
@@ -1323,21 +1323,20 @@
 n encode
-(k
+dK
 ey
-)
  + '=' +
@@ -1346,18 +1346,14 @@
 code
-(obj%5Bkey%5D)
+dValue
 ;%0A  

add encodeCookieComponent function