Skip to content

Commit

Permalink
Improve error message when encode is not a function
Browse files Browse the repository at this point in the history
closes #40
  • Loading branch information
David Nunez authored and dougwilson committed May 26, 2016
1 parent 71dbc9e commit cabcda0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Expand Up @@ -3,6 +3,7 @@ unreleased

* Add `sameSite` option
- Replaces `firstPartyOnly` option, never implemented by browsers
* Improve error message when `encode` is not a function

0.2.4 / 2016-05-20
==================
Expand Down
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -102,6 +102,10 @@ function serialize(name, val, options) {
var opt = options || {};
var enc = opt.encode || encode;

if (typeof enc !== 'function') {
throw new TypeError('option encode is invalid');
}

if (!fieldContentRegExp.test(name)) {
throw new TypeError('argument name is invalid');
}
Expand Down
1 change: 1 addition & 0 deletions test/serialize.js
Expand Up @@ -11,6 +11,7 @@ test('basic', function() {
assert.equal('foo=', cookie.serialize('foo', ''));
assert.throws(cookie.serialize.bind(cookie, 'foo\n', 'bar'), /argument name is invalid/);
assert.throws(cookie.serialize.bind(cookie, 'foo\u280a', 'bar'), /argument name is invalid/);
assert.throws(cookie.serialize.bind(cookie, 'foo', 'bar', {encode: 42}), /option encode is invalid/);
});

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

0 comments on commit cabcda0

Please sign in to comment.