BitzArt / Blazor.Cookies

Working with browser cookies in Blazor United
MIT License
31 stars 5 forks source link

Can cookies have "=" in the value? #8

Closed scastria closed 3 weeks ago

scastria commented 4 weeks ago

I converted my cookie value to base64 and stored it. However, when I tried to read it back, I get "Invalid cookie format" because this package is splitting the string on the equals sign. Base64 uses equals signs causing the error. Are cookies allowed to have equals signs inside the value?

YuriyDurov commented 4 weeks ago

Hello @scastria,

Equals signs are treated as separators in cookies, and thus can not be used in the value.

You could try encoding your value before setting it in the cookie, and decoding it when reading it back.

Also, equals signs are just for padding in base64, so you could probably just trim those, too. It should not affect the actual value.