Mojolicious template displaying invalid UTF-8

lepe

I'm using Mojolicious (not Lite) together with CPAN::Redis.

I'm storing some data which is Japanese encoded in this way:

use Redis;
my $redis = Redis->new;
$redis->set("mykey",$val); 
# $val contains a string which was read from a file. 
# The value looks like: テスト

Later in the code I read that value from redis:

my $val = $redis->get("mykey");
print Dumper($val); #the value prints correctly in terminal
$self->stash(
    myvalue => $val
);
$self->render(
    template => "/pages/test"
);

And the template:

<!DOCTYPE html>
<html>
  <head>
      <title>Test</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  </head>
  <body>
  <div><%= $myvalue %></div>
  ...

But it display the value like: ãã¹ã.

Changing the charset manually in the browser makes no difference (it is not displayed as expected).

Why if its displayed correctly in the terminal, it is not displayed correctly in the template?

Notes:

  • I used base64 encode/decode and it didn't change (I'm sure its not Redis).
  • I have Japanese fonts and settings installed correctly (I have been working with Japanese encodings for many years but first time I use Mojolicious templates for this task).
  • All files are saved in UTF-8 (no other encoding is being used).
  • If I write something in Japanese inside the template (hard coded) it displays correctly.
lepe

I hate to answer my own questions.. but I found the solution:

use Encode qw(decode_utf8);
...
$self->stash(
    myvalue => decode_utf8($val)
);

Simple as that. Not sure why its displayed correctly on the terminal... Probably "Dumper" is converting it?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Filtering invalid utf8

From Dev

Special characters UTF8 not displaying in safari

From Dev

Terminal not displaying UTF-8 character(s)

From Dev

encoding error in Mojolicious' template

From Dev

Invalid Byte Sequence In UTF-8 Ruby

From Dev

invalid UTF-8 code sequence

From Dev

Invalid byte sequence in UTF-8 (ArgumentError)

From Dev

jmeter Invalid UTF-8 middle byte

From Dev

Invalid UTF-8 sequence in argument with Laravel

From Dev

Openshift: invalid byte sequence in UTF-8

From Dev

How to deal with invalid utf8 in fileinput?

From Dev

Browser displaying page in UTF-8 instead of windows-1251

From Dev

Why Eclipse does not displaying UTF-8 chars

From Dev

Laravel not displaying special UTF8 characters on 'public' server

From Dev

JqueryMobile ajax load special characters in utf-8 not displaying

From Dev

Unix shell not displaying UTF8 line drawing symbols

From Dev

WebClient DownloadString UTF-8 not displaying international characters

From Dev

Displaying UTF-8 codes from JSON file as Emoticons

From Dev

Getting a utf-8 encoded string from a database, then displaying in a webview

From Dev

UTF-8 Charset displaying french characters incorrectly.

From Dev

UTF-8 not displaying correctly in Cygwin+zsh using ConEmu

From Dev

UTF-8 Special Characters in PHP/Codeigniter not displaying correctly

From Dev

Why Eclipse does not displaying UTF-8 chars

From Dev

Creating recursive template blocks in Mojolicious

From Dev

Base url in Mojolicious template rendering

From Dev

ActionView::Template::Error (Your template was not saved as valid utf-8

From Dev

How to replace invalid UTF8 chars with spaces

From Dev

Rails Import CSV Error: invalid byte sequence in UTF-8

From Dev

How to convert filename with invalid UTF-8 characters back to bytes?

Related Related

  1. 1

    Filtering invalid utf8

  2. 2

    Special characters UTF8 not displaying in safari

  3. 3

    Terminal not displaying UTF-8 character(s)

  4. 4

    encoding error in Mojolicious' template

  5. 5

    Invalid Byte Sequence In UTF-8 Ruby

  6. 6

    invalid UTF-8 code sequence

  7. 7

    Invalid byte sequence in UTF-8 (ArgumentError)

  8. 8

    jmeter Invalid UTF-8 middle byte

  9. 9

    Invalid UTF-8 sequence in argument with Laravel

  10. 10

    Openshift: invalid byte sequence in UTF-8

  11. 11

    How to deal with invalid utf8 in fileinput?

  12. 12

    Browser displaying page in UTF-8 instead of windows-1251

  13. 13

    Why Eclipse does not displaying UTF-8 chars

  14. 14

    Laravel not displaying special UTF8 characters on 'public' server

  15. 15

    JqueryMobile ajax load special characters in utf-8 not displaying

  16. 16

    Unix shell not displaying UTF8 line drawing symbols

  17. 17

    WebClient DownloadString UTF-8 not displaying international characters

  18. 18

    Displaying UTF-8 codes from JSON file as Emoticons

  19. 19

    Getting a utf-8 encoded string from a database, then displaying in a webview

  20. 20

    UTF-8 Charset displaying french characters incorrectly.

  21. 21

    UTF-8 not displaying correctly in Cygwin+zsh using ConEmu

  22. 22

    UTF-8 Special Characters in PHP/Codeigniter not displaying correctly

  23. 23

    Why Eclipse does not displaying UTF-8 chars

  24. 24

    Creating recursive template blocks in Mojolicious

  25. 25

    Base url in Mojolicious template rendering

  26. 26

    ActionView::Template::Error (Your template was not saved as valid utf-8

  27. 27

    How to replace invalid UTF8 chars with spaces

  28. 28

    Rails Import CSV Error: invalid byte sequence in UTF-8

  29. 29

    How to convert filename with invalid UTF-8 characters back to bytes?

HotTag

Archive