Skip to content

Instantly share code, notes, and snippets.

/utf8.pl Secret

Created October 6, 2014 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/27cbeca7efb952cda71a to your computer and use it in GitHub Desktop.
Save anonymous/27cbeca7efb952cda71a to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use Mojo::Base -strict;
use Test::More;
use Test::Mojo;
use Mojolicious::Lite;
use JSON::Any;
use Mojo::Util qw/url_unescape/;
get '/:xyz' => sub {
my $c = shift;
my $data = $c->param('xyz');
# That's basically what MooseX::Storage::Format::JSON does.
my $json = JSON::Any->new(canonical => 1)->objToJson( [$data] );
# And it works just fine without the following line
utf8::decode($json) if !utf8::is_utf8($json) and utf8::valid($json);
$c->render(text => $json);
};
my $t = Test::Mojo->new;
$t->get_ok('/foo')->content_is('["foo"]');
my $string = '%C3%B6%C3%A4%C3%BC';
$t->get_ok('/'.$string)->content_is('["'.url_unescape($string).'"]');
done_testing();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment