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

Inconsistent encoding? #109

Closed
pmichna opened this issue Oct 30, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@pmichna
Copy link

commented Oct 30, 2015

I want to save current date in a cookie with:

Cookies.set('discount_timer', new Date())

new Date() returns Fri Oct 30 2015 09:45:30 GMT+0100 (CET)

What is really saved in the cookie is:

Fri%20Oct%2030%202015%2009:45:30%20GMT+0100%20(CET)

Why isn't the plus sign after "GMT" encoded while the spaces are encoded?

@pmichna pmichna changed the title Inconsisten encoding? Inconsistent encoding? Oct 30, 2015

@FagnerMartinsBrack

This comment has been minimized.

Copy link
Member

commented Nov 1, 2015

Hi, thanks for creating the issue.

The docs says that:

When creating a cookie you can pass an Array or Object Literal instead of a string in the value.

Therefore, the only supported types in the cookie value are a String, an Object Literal and an Array, the behavior is undefined for any other type that is passed instead of the ones that are documented.

Why isn't the plus sign after "GMT" encoded while the spaces are encoded?

The docs says that:

This project is RFC 6265 compliant. All special characters that are not allowed in the cookie-name or cookie-value are encoded with each one's UTF-8 Hex equivalent using percent-encoding.
The only character in cookie-name or cookie-value that is allowed and still encoded is the percent % character, it is escaped in order to interpret percent input as literal.

According to RFC 6265, the "plus sign" is allowed in the cookie value (see the %x23-2B part in section 4.1.1), therefore it doesn't need to be encoded.

This is not inconsistent encoding, it is actually pretty consistent according to the official cookie RFC.

@FagnerMartinsBrack FagnerMartinsBrack added this to the v2.0.5 milestone Nov 1, 2015

@pmichna

This comment has been minimized.

Copy link
Author

commented Nov 2, 2015

Maybe it would be a good idea to make it possible to save values in cookies with encoded '+' sign (or any others)? There is a converter that can read values from cookies. What about something similar for writing values to cookies?

Current situation hurts me, because I'm trying to use cookie values in my Rails application which tries to decode every character, so it treats '+' as space.

@FagnerMartinsBrack

This comment has been minimized.

Copy link
Member

commented Nov 2, 2015

Current situation hurts me

We are aware of that.

What about something similar for writing values to cookies?

Definitely, see #71. I plan releasing it for 2.1.0, with no ETA. In the meantime you can build the write-converters branch.

You can find additional docs in the branch above here (in development).

@FagnerMartinsBrack FagnerMartinsBrack modified the milestones: v2.1.0, v2.0.5 Nov 8, 2015

@FagnerMartinsBrack

This comment has been minimized.

Copy link
Member

commented Nov 8, 2015

I just merged the write converter in the master branch. It will be available in version 2.1.0 later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.