Skip to content

Test the behavior for undefined value in custom attributes #59

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

Closed
wants to merge 1 commit into from

Conversation

FagnerMartinsBrack
Copy link
Member

A few months ago @Krinkle identified an API problem when passing undefined to the cookie value. Basically in that situation, the return of a function that is supposed to generate a cookie value should not be interpreted as a getter.

Now we have a similar situation with the cookie attributes. The documentation doesn't say that undefined is a valid input for a cookie attribute, so the intent of the code just assumes the value will be truthy and uses && to check for it. The only actual benefit of using logical && operator was to reduce a few bytes gzipped when they were removed in bulk here.

Fortunately, [undefined].join('') returns "" in the operation to persist the cookie, so it doesn't write c=v; path=/undefined for domain: undefined like what happened to the expires: false attribute.

Unfortunately that is not tested.

  • This PR test the behavior to ensure that if the code changes, the behavior will always stay the same.
  • In other hand I don't know if the test is entirely necessary, because it also define a noop behavior for the undefined value, which might not be wise since it will become implicitly supported and cannot be changed in any future minor version bump.

Example:

var domain = getDomain(); // returns undefined
Cookies.set('name', 'value', {
    domain: domain
    // domain: undefined
});

Is it worth testing this behavior?

@FagnerMartinsBrack
Copy link
Member Author

@carhartl Do you agree to support undefined in the cookie attributes as noop?

@carhartl
Copy link
Member

Yes, I think this is reasonable.

@FagnerMartinsBrack FagnerMartinsBrack deleted the test-undefined-value-attributes branch July 15, 2015 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants