Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ If the signature cookie _does_ exist, the provided [Keygrip](https://www.npmjs.c

This sets the given cookie in the response and returns the current context to allow chaining.

If the _value_ is omitted, an outbound header with an expired date is used to delete the cookie.
If the _value_ is omitted (or `null`), an outbound header with an expired date is used to delete the cookie. If _value_ is not omitted, it _must_ be given as string.

If the _options_ object is provided, it will be used to generate the outbound cookie header as follows:

Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ function Cookie(name, value, attrs) {
throw new TypeError('argument name is invalid');
}

if (value !== undefined && value !== null && typeof value !== 'string') {
throw new Error('argument value is not a string');
}

if (value && !fieldContentRegExp.test(value)) {
throw new TypeError('argument value is invalid');
}
Expand Down
12 changes: 12 additions & 0 deletions test/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ describe('new Cookie(name, value, [options])', function () {
}, /option domain is invalid/)
})

it('should throw on number value', function () {
assert.throws(function () {
new cookies.Cookie('foo', 0)
}, /argument value is not a string/)
})

it('should throw on boolean value', function () {
assert.throws(function () {
new cookies.Cookie('foo', false)
}, /argument value is not a string/)
})

describe('options', function () {
describe('maxage', function () {
it('should set the .maxAge property', function () {
Expand Down