Navigation Menu

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

Cookies.get(undefined) returns all cookies #399

Closed
sammok opened this issue Jan 25, 2018 · 13 comments
Closed

Cookies.get(undefined) returns all cookies #399

sammok opened this issue Jan 25, 2018 · 13 comments
Assignees
Milestone

Comments

@sammok
Copy link

sammok commented Jan 25, 2018

Dear developer,

When I use Cookies.get() method, I passing a undefined variable as a parameter into get method,

bug returns all cookies,

I think, Cookie.get() method should checking the arguments length, if arguments.length > 0, this method shouldn't returns all the cookies, returns undefined would be better.

Test Case:

console.log(Cookies.get(), Cookies.get(undefined), Cookies.get(null))
output: {}, {}, {}

expect

console.log(Cookies.get(), Cookies.get(undefined), Cookies.get(null))
output: {}, undefined, undefined
@FagnerMartinsBrack
Copy link
Member

FagnerMartinsBrack commented Jan 25, 2018

Cookies.get(undefined) is not documented - e.g there's no such API. Why are you using the API like that? Can you share some examples?

@FagnerMartinsBrack
Copy link
Member

Closing due to the lack of feedback from the OP. If you want to continue the discussion, please comment here mentioning one of the project members.

@jackocnr
Copy link

Hi there, I've recently hit a related issue - if I have the cookie name in a variable, and in some situations I need to be able to handle where that variable is not set, or it has a default value like null or empty string, in those cases it makes more sense to me for get to return null instead of all of the cookies. As the op says, if I pass in a value, then I think it shows an intent to fetch a particular cookie, and certainly not all of the cookies.

Honestly it just feels dangerous to use the same get method for two completely different use cases, to retrieve two different data types. I would favour get always being to get a particular cookie, and having some new method e.g. getAll if you want to get all cookies, to make it explicit. What do you think?

@FagnerMartinsBrack
Copy link
Member

Opening due to @jackocnr feedback. In this case, we should be doing if arguments.length > 0. Similar problem as of carhartl/jquery-cookie#308

@jackocnr do you want to create a test and PR for this?

@jackocnr
Copy link

Thanks for your response. I'm very busy at the mo, but I might be able to take a look one weekend if I find the time.

@FagnerMartinsBrack
Copy link
Member

Sure @jackocnr feel free to take the time it takes :)

@FagnerMartinsBrack
Copy link
Member

@jackocnr any news on this?

@jackocnr
Copy link

Nope. It's still on my list, but I haven't found the time yet.

@carhartl carhartl modified the milestones: v2.2.1, v3.0.0 Sep 5, 2019
@carhartl
Copy link
Member

I believe we can change

return key ? jar[key] : jar

to

return arguments.length >= 1 ? jar[key] : jar

Will tackle this later..

@carhartl
Copy link
Member

Ha, that would have worked if it was not for getJSON()...

@carhartl carhartl assigned carhartl and unassigned jackocnr Sep 13, 2019
@FagnerMartinsBrack
Copy link
Member

FagnerMartinsBrack commented Sep 14, 2019

@carhartl Is it time to dump getJSON either in favor of people doing JSON.stringify(Cookies.get('name')), Cookies.get('name', JSON.parse(value))? I don't see a valid point in encouraging things like Cookies.getJSON().a.foo.bar -> If one level of JSON is removed from the store, the code crashes.

@carhartl
Copy link
Member

Is it time to dump getJSON

I didn't even think of that.. open a ticket and try to gather some thoughts?

@FagnerMartinsBrack
Copy link
Member

@carhartl #540

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

No branches or pull requests

4 participants