UTF8 bug with sha1_sum/md5_sum

94 views
Skip to first unread message

Valuyskiy Alex

unread,
Jun 2, 2013, 7:09:57 AM6/2/13
to mojol...@googlegroups.com
I can not use cyrillic (or another non-latin symbols) words for these methods: sha1_sum/md5_sum.
When I use they I see a bug: Wide character in subroutine entry at /usr/local/share/perl/5.14.2/Mojo/Util.pm line 262.

Also, why non-lating symbols display incorrectly on an error pages? http://prntscr.com/17vlug

Alexandre Zaitsev

unread,
Jun 3, 2013, 10:21:14 AM6/3/13
to mojol...@googlegroups.com
It is because functions from Digest::* modules doesn't support wide characters.
You need to convert your string to bytes:

use Encode qw( encode_utf8 is_utf8 );
my $source_string = "...";
my $suitable = is_utf8( $source_string ) ? encode_utf8( $source_string ) : $source_string;
..now you can get SHA1/MD5/... from $suitable

BTW, there is an exellent description of Perl's unicode stuff in Russian: http://habrahabr.ru/post/53578/


воскресенье, 2 июня 2013 г., 15:09:57 UTC+4 пользователь Valuyskiy Alex написал:

Valuyskiy Alex

unread,
Jun 6, 2013, 10:38:07 AM6/6/13
to mojol...@googlegroups.com
Thank you.

Also i have a troubles, when i get non-latin text from websockets
воскресенье, 2 июня 2013 г., 14:09:57 UTC+3 пользователь Valuyskiy Alex написал:

Valuyskiy Alex

unread,
Jun 14, 2013, 9:38:33 AM6/14/13
to mojol...@googlegroups.com
What about the second question?

Alexandre Zaitsev

unread,
Jun 24, 2013, 2:54:39 AM6/24/13
to mojol...@googlegroups.com
The problem is almost similar. Mojolicious uses Data::Dumper to generate exception pages. And Data::Dumper displays utf8-encoded strings in it's hexademical representation. If your data in stash hadn't been encoded in utf8, you would have got 'normal' symbols in dumper output. But I don't know easy solution in this case -- I suppose, you can't control where you'll get an exception to be able to convert your data in stash just before rendering :-)
There is another way -- you can create your own exception page (name it as "exception.html.ep" and put into your templates directory), where you can dump stash values using YAML, for example, that doesn't have such problems.


пятница, 14 июня 2013 г., 17:38:33 UTC+4 пользователь Valuyskiy Alex написал:

Sergey Dmitriev

unread,
Jun 24, 2013, 3:03:31 AM6/24/13
to mojol...@googlegroups.com
BTW, if you need to dump non-latin data correctly (i.e. human-readable) using Data::Dumper or Data::Dumper::Concise, you have to redefine qquote somewhere in your code, like this:

use Data::Dumper::Concise;

$Data::Dumper::Useqq = 1;

{ no warnings 'redefine';
    sub Data::Dumper::qquote {
        my $s = shift;
        return "'$s'";
    }
}

I've seen this hack somewhere on perlmonks. This way, Dumper will not escape non-latin thus they will be shown in human-readable form.


HtH, Sergey Dmitriev
"All that is necessary for evil to triumph is for good men to do nothing". -- Edmund Burke


2013/6/24 Alexandre Zaitsev <a.za...@drweb.com>
--
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 mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages