arg20
arg20

Reputation: 4991

ExpressJS unicode cookie

Is there any way to send unicode values in a cookie in expressjs. When a user is using a Spanish locale, a cookie is serialized with the user name, which can be something like "José"

e.g:

 res.cookie('user', JSON.stringify({name: 'José'}));

However in the client I get a cookie with the value:

{name: 'José'}

is there any way around this? The server already outputs that.

Upvotes: 1

Views: 332

Answers (1)

marton
marton

Reputation: 1350

To be able to use unicode characters in a cookie, you should use an encoding scheme.

encodeURIComponent() or querystring.escape() in node when setting the cookie and decodeURIComponent() in the client should work.

It's not specific to express, but how cookies work in general. See this answer for details: Allowed characters in cookies

Upvotes: 2

Related Questions