Encoding pitfall


I had a problem with toots and tweets encoding, the net helped solve it with How to make Mojolicious deal with UTF-8?

When previous post Bézier curves (note the LATIN SMALL LETTER E WITH ACUTE) was automatically published by busypub, the Notifications for busypub kicked in but something went wrong with the published messages and I got Bézier instead.

How 2000-ish!

How to make Mojolicious deal with UTF-8? got me on the right track:

As such, $res->body is bytes, $res->text is text decoded from encoding specified in response.

This prompted me to do this change:

    my $res = Mojo::UserAgent->new(max_redirect => 5)->get($uri)->result;
    die "error getting ($uri): " . $res->message
      unless $res->is_success;
-   (my $body = $res->body) =~ s{\A\s+|\s+\z}{}gmxs;
+   (my $body = $res->text) =~ s{\A\s+|\s+\z}{}gmxs;
    my ($date, $status) = split m{\n}mxs, $body, 2;
    return {
       date   => $date,

i.e. switching from considering the notification I was fetching with Mojo::UserAgent as sequence of bytes and start considering it… text made of characters.

And it worked:

toot with bézier written right

Time and again, Mojolicious and the Mojo framework prove to be just… right and amazing.

Comments? Octodon, , GitHub, Reddit, or drop me a line!