Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail on non ascii symbols #430

Closed
nwtour opened this issue Dec 18, 2012 · 7 comments
Closed

fail on non ascii symbols #430

nwtour opened this issue Dec 18, 2012 · 7 comments

Comments

@nwtour
Copy link

nwtour commented Dec 18, 2012

Code (used toto framework, body russian UTF-8):

use Mojolicious::Lite;
use utf8;

plugin 'toto' =>
            nav => [ 'Файл', 'Папки', 'Другое' ],
            sidebar => { 'Файл'   => [ 'Файл', 'Файл/Создать'  ],
                         'Папки'  => [ 'Папки', 'Папки/Создать'],
                         'Другое' => [ 'Другое'                ] },
            tabs => {
                'Файл'   => [ 'Просмотр', 'Редактирование', 'Удалить' ],
                'Папки'  => [ 'Просмотр', 'Редактирование', 'Удалить' ],
                'Другое' => [ 'Просмотр', 'Редактирование', 'Удалить' ],
            };

app->start;

On request:

[Tue Dec 18 22:08:10 2012] [fatal] Processing request failed: Can't use global $^þ¿¿¿¾Â¤Ã°Ã¹Ã» in "my" at inline template line 1, near "my $Файл "

Patch (workaround?):


--- /usr/local/lib/perl5/site_perl/5.14.2/Mojo/Template.pm.orig 2012-12-18 22:15:13.000000000 +0400
+++ /usr/local/lib/perl5/site_perl/5.14.2/Mojo/Template.pm      2012-12-18 22:08:36.000000000 +0400
@@ -317,7 +317,7 @@
 
   # Wrap lines
   my $first = $lines->[0] ||= '';
-  $lines->[0] = "package @{[$self->namespace]}; use Mojo::Base -strict;";
+  $lines->[0] = "package @{[$self->namespace]}; use Mojo::Base -strict; use utf8;";
   $lines->[0]  .= "sub { my \$_M = ''; @{[$self->prepend]}; do { $first";
   $lines->[-1] .= "@{[$self->append]}; \$_M } };";

Thanks you!

@jberger
Copy link
Member

jberger commented Dec 18, 2012

I'm not sure about the order of loading, but can't you toss the use utf8; into the prepend attribute?

@nwtour
Copy link
Author

nwtour commented Dec 18, 2012

Why not? $Mojo::Template::code its evaluated code.

nwtour@/tmp $ cat test.pl

#!/usr/bin/env perl

sub gen_template {
    my $u = shift;

return q{
package Mojo::Template::SandBox;
use Mojo::Base -strict;

} . ( $u ? 'use utf8;' : '' ) . q{

no warnings 'redefine';
use strict;
my $_S = undef; # $self->stash;
my $Файл = $_S->{'Файл'};
};

}

eval gen_template( 1 );

print "example one: " . ( $@ ? 'fail' : 'ok' ) . "\n";

eval gen_template( 0 ) ;

print "example two: " . ( $@ ? 'fail' : 'ok' ) . "\n";

nwtour@/tmp $ perl test.pl
example one: ok
example two: fail

@jberger
Copy link
Member

jberger commented Dec 18, 2012

Can I ask you to please use markdown code formatting on your examples? Thanks.

Here is my example:

#!/usr/bin/env perl

use strict;
use warnings;

use Mojo::Template;
my $t = Mojo::Template->new(
  prepend => 'use utf8;',
);

my $rendered = $t->render( <<'END' );
  % my $Файл = 'Файл';
  %= $Файл
END

# prevent "wide character" warning
use open qw{:encoding(UTF-8) :std};
print $rendered;

This seems to run just fine. Further, putting use utf8::all at the top seemed to make it work too.

@nwtour
Copy link
Author

nwtour commented Dec 18, 2012

Markdown done (Sorry i`m noobie on github)

This bug depended on perl compile options, on my home computer bug unreproduced (work in the box), but I compile vanila perl with default options and bug returned.

probably cause:

Compile-time options: USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC

About "prepend" - now i`m understand. Its cool and its work! But i dont find place to patch Mojolicious::Plugin::Toto
https://metacpan.org/source/BDUGGAN/Mojolicious-Plugin-Toto-0.21/lib/Mojolicious/Plugin/Toto.pm
Plugin used Mojo::Base and hack with "prepend" is dirty.

Subject bug in line 324: https://metacpan.org/source/BDUGGAN/Mojolicious-Plugin-Toto-0.21/lib/Mojolicious/Plugin/Toto.pm#L324

Stash key as utf8 string IMHO its normal situation, agree?

@marcusramberg
Copy link
Member

I'm wondering if this would be fixed by 34d8bfa ?

@xuntaka
Copy link

xuntaka commented Dec 26, 2012

Yeah! utf8->import by default!

@nwtour
Copy link
Author

nwtour commented Dec 26, 2012

Yes! Patch from 34d8bfa resolve this issue.

Many thanks Joel and Sebastian.

@nwtour nwtour closed this as completed Dec 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants