Reputation: 41
I am trying to set a session cookie to save an Address. Every time I save the cookie that contains comma followed by space, Safari strips out the space after the commas and breaks the format.
// JavaScript code to save the cookie
document.cookie = "Address=Sample Address, Ontario, Canada;path=/;expire=0;";
// Result
document.cookie => "Address=Sample Address,Ontario,Canada"
Is there any solution to this behaviour? Can we somehow tell Safari not to strip the spaces?
Safari Version 10.1.2 (12603.3.8) | MacOS Sierra Version 10.12.6
Upvotes: 2
Views: 459
Reputation: 274
The easiest way I found and solved is by UriEncoding the value of the cookie you are trying to set. And decoding the same when you are reading the value of the cookie.
Upvotes: 1