diff --git a/index.js b/index.js index 3672dfc..2fe8985 100644 --- a/index.js +++ b/index.js @@ -162,7 +162,7 @@ Cookie.prototype.toString = function() { Cookie.prototype.toHeader = function() { var header = this.toString() - if (this.maxAge) this.expires = new Date(Date.now() + this.maxAge); + if (this.maxAge || 0 === this.maxAge) this.expires = new Date(Date.now() + this.maxAge); if (this.path ) header += "; path=" + this.path if (this.expires ) header += "; expires=" + this.expires.toUTCString() diff --git a/test/cookie.js b/test/cookie.js index 347c2e8..d20b2ce 100644 --- a/test/cookie.js +++ b/test/cookie.js @@ -55,6 +55,11 @@ describe('new Cookie(name, value, [options])', function () { var cookie = new cookies.Cookie('foo', 'bar', { maxAge: 86400 }) assert.equal(cookie.maxage, 86400) }) + + it('should set the .maxAge property to 0', function () { + var cookie = new cookies.Cookie('foo', 'bar', { maxAge: 0 }) + assert.equal(cookie.maxAge, 0) + }) }) describe('sameSite', function () {