From 8cd865237effee9b3e2db1ad7e28b8a71c591e4b Mon Sep 17 00:00:00 2001 From: Tiago Rodrigues Date: Tue, 19 Feb 2013 16:13:00 +0000 Subject: [PATCH 1/2] don't override options.expires if it's been defined --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 6a9d645..0fbc897 100644 --- a/index.js +++ b/index.js @@ -47,7 +47,7 @@ function set(name, value, options) { if (null == value) options.maxage = -1; - if (options.maxage) { + if (options.maxage && !options.expires) { options.expires = new Date(+new Date + options.maxage); } From 9583f6ea6ac88082dc36969f167e5898b7797f81 Mon Sep 17 00:00:00 2001 From: Tiago Rodrigues Date: Tue, 19 Feb 2013 17:54:02 +0000 Subject: [PATCH 2/2] move toUTCString call to ensure it gets called on the date object --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0fbc897..d0c42fd 100644 --- a/index.js +++ b/index.js @@ -48,12 +48,12 @@ function set(name, value, options) { if (null == value) options.maxage = -1; if (options.maxage && !options.expires) { - options.expires = new Date(+new Date + options.maxage); + options.expires = (new Date(+new Date + options.maxage)).toUTCString(); } if (options.path) str += '; path=' + options.path; if (options.domain) str += '; domain=' + options.domain; - if (options.expires) str += '; expires=' + options.expires.toUTCString(); + if (options.expires) str += '; expires=' + options.expires; if (options.secure) str += '; secure'; document.cookie = str;