cmp-cc / vue-cookies

A simple Vue.js plugin for handling browser cookies
MIT License
408 stars 70 forks source link

Why do you use `encodeURIComponent` when setting the key? #32

Closed dmuneras closed 4 years ago

dmuneras commented 5 years ago

Hi!

I would love to know why do you use encodeURIComponent when setting the cookie. it could be problematic if you have cookie keys that includes: ":". example: my-app:cool-cookie

Best regards, Daniel.

cmp-cc commented 5 years ago

The cookie value string can use encodeURIComponent() to ensure that the string does not contain any commas, semicolons, or whitespace (which are disallowed in cookie values).

encodeURIComponent/decodeURIComponent escape sequences (e.g. comma, quotes, [], : , ; etc)

example:

// set
encodeURIComponent('my-app:cool-cookie') // "my-app%3Acool-cookie"

// get
decodeURIComponent("my-app%3Acool-cookie") // "my-app:cool-cookie"