Skip to content

Commit

Permalink
Fix cookie Max-Age to never be a floating point number
Browse files Browse the repository at this point in the history
closes #39
  • Loading branch information
David Nunez authored and dougwilson committed Oct 26, 2015
1 parent 7ebfa14 commit ba8bd30
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased
==========

* Fix cookie `Max-Age` to never be a floating point number

0.2.2 / 2015-09-17
==================

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function serialize(name, val, options) {
if (null != opt.maxAge) {
var maxAge = opt.maxAge - 0;
if (isNaN(maxAge)) throw new Error('maxAge should be a Number');
pairs.push('Max-Age=' + maxAge);
pairs.push('Max-Age=' + Math.floor(maxAge));
}

if (opt.domain) {
Expand Down
20 changes: 20 additions & 0 deletions test/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,29 @@ test('maxAge', function() {
maxAge: 1000
}));

assert.equal('foo=bar; Max-Age=1000', cookie.serialize('foo', 'bar', {
maxAge: '1000'
}));

assert.equal('foo=bar; Max-Age=0', cookie.serialize('foo', 'bar', {
maxAge: 0
}));

assert.equal('foo=bar; Max-Age=0', cookie.serialize('foo', 'bar', {
maxAge: '0'
}));

assert.equal('foo=bar', cookie.serialize('foo', 'bar', {
maxAge: null
}));

assert.equal('foo=bar', cookie.serialize('foo', 'bar', {
maxAge: undefined
}));

assert.equal('foo=bar; Max-Age=3', cookie.serialize('foo', 'bar', {
maxAge: 3.14
}));
});

test('firstPartyOnly', function() {
Expand Down

0 comments on commit ba8bd30

Please sign in to comment.