Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slight improvements to options object member validation #40

Closed
wants to merge 1 commit into from
Closed

Slight improvements to options object member validation #40

wants to merge 1 commit into from

Conversation

arizonatribe
Copy link

Explicitly checking for options object members expected data types (typeof 'function' for encode/decode, valid Date or date strings for expiration, valid string values for domain and path), also using shorthand for "if value is acceptable add to array" logic.

if (opt.expires) pairs.push('Expires=' + opt.expires.toUTCString());
if (opt.httpOnly) pairs.push('HttpOnly');
if (opt.secure) pairs.push('Secure');
typeof opt.domain === 'string' && pairs.push('Domain=' + opt.domain);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo these changes so they are actual if statements.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified to be if statements as per your request

@dougwilson dougwilson added the pr label Jul 10, 2015
@dougwilson dougwilson self-assigned this Jul 10, 2015
test('encoded method validation', function() {
assert.throws(cookie.serialize.bind(null, 'cat', ' ', {
encode: 42
}), /number is not a function/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is failing on io.js 2.x due to a difference in the v8 error message.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that earlier and threw in a regex that should cover it in either case. Let me know though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just throw our own error, so the message is predictable (and probably more helpful to users)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, added code to throw after parsing encode

dougwilson pushed a commit that referenced this pull request May 26, 2016
@dougwilson
Copy link
Contributor

Sorry @arizonatribe that I had neglected this pull request. I have cherry-picked the couple checks that were definitely backwards-compatible so we can use at least something from the pull request (it's not always easy to accept a PR when it does several different things, and some have issues while other changes do not). Please feel free to make a new PR adding any additional checks you would like and we can get it into the 1.0 coming up soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants