From c391e2570c69d81c4fb1f89e8135cb03f597cb50 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 24 Mar 2016 07:11:15 -0200 Subject: [PATCH] fix utf8 in url --- lib/Dancer2/Core/Request.pm | 2 +- t/utf8.t | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 t/utf8.t diff --git a/lib/Dancer2/Core/Request.pm b/lib/Dancer2/Core/Request.pm index 059453c31..9cd1689f7 100644 --- a/lib/Dancer2/Core/Request.pm +++ b/lib/Dancer2/Core/Request.pm @@ -282,7 +282,7 @@ sub dispatch_path { $path =~ s|^/+|/|; # PSGI spec notes that '' should be considered '/' $path = '/' if $path eq ''; - return $path; + return Encode::decode('utf8', $path); } sub uri_for { diff --git a/t/utf8.t b/t/utf8.t new file mode 100644 index 000000000..3b8d6392c --- /dev/null +++ b/t/utf8.t @@ -0,0 +1,33 @@ +use utf8; +use strict; +use warnings; + +use Test::More; +use Plack::Test; +use HTTP::Request::Common; +use Encode; + +my $utf8 = 'ľščťžýáí'; + +{ + package MyApp; + + use Dancer2; + use utf8; + + get '/ľščťžýáí' => sub { + return 'ľščťžýáí'; + }; +} + +my $app = Dancer2->psgi_app; + +test_psgi $app, sub { + my $cb = shift; + + my $res = $cb->( GET '/ľščťžýáí' ); + is $res->code, 200; + is Encode::decode('utf8', $res->content), 'ľščťžýáí'; +}; + +done_testing();