Note that you can tell it not to b64 with newlines by passing a different
separator. http://mojolicious.org/perldoc/Mojo/Util#b64_encode
my $b64 = b64_encode $bytes, '';
On Thursday, January 7, 2016 at 12:20:12 PM UTC-6, Juergen Nickelsen wrote:
>
> Just an observation I made today: If the value of a cookie that I set
> with $c->cookie($name) ends with a newline, the cookie's attributes are
> not set. Example:
>
> $c->cookie($cookie_name, $encoded_cookie,
> {
> path => '/',
> expires => $cookie_lifetime + time(),
> });
>
> $encoded_cookie is a base64-encoded JSON string, and in the first
> attempt I wasn't aware that Mojo::Util::b64_encode() ends the encoded
> content with a newline. As a result, the Set-Cookie header field ends
> right after the cookie value, path and expires not being set:
>
> Set-Cookie: service_prefs=rlWfLJ5aVwbvMTHvsD==
>
> When, on the other hand, I chomp() the newline off the cookie value
> before setting it, the result is fine:
>
> Set-Cookie: service_prefs=rlWfLJ5aVwbvMJ4vsD==; expires=Sun, 21 Dec 2025
> 20:42:47 GMT; path=/
>
> Chomping the newline off the value could be done by Mojolicious to
> prevent this mishap. As there may be valid reasons not to do it that I
> am not a aware of, I don't know if this is a bug or intentional
> behaviour. At least, I found it surprising.
>
> So, *if* this is just a bug or oversight, I am all for removing an
> existing newline from the cookie value by default.
>
> Regards, Juergen.
>
> --
> <[email protected]> Tel +49.30.838-50740 Fax -450740
> Zentraleinrichtung fuer Datenverarbeitung, Central Systems (Unix)
> Freie Universitaet Berlin, Fabeckstrasse 32, 14195 Berlin, DE
>
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.