Created
February 18, 2011 11:03
-
-
Save tomyhero/833544 to your computer and use it in GitHub Desktop.
args encode patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -x .git -urN Pickles-origin/lib/Pickles/Plugin/Encode.pm Pickles/lib/Pickles/Plugin/Encode.pm | |
--- Pickles-origin/lib/Pickles/Plugin/Encode.pm 2011-02-18 18:52:18.000000000 +0900 | |
+++ Pickles/lib/Pickles/Plugin/Encode.pm 2011-02-18 19:58:34.000000000 +0900 | |
@@ -19,6 +19,17 @@ | |
my $ie = $config->{input_encoding} || 'utf-8'; | |
_decode( $c->req->query_parameters, $ie ); | |
_decode( $c->req->body_parameters, $ie ); | |
+ for my $key (keys %{$c->args}){ | |
+ if( ref $c->args->{$key} eq 'ARRAY'){ | |
+ my $array = $c->args->{$key}; | |
+ for(my $i = 0 ; $i < scalar @$array; $i++){ | |
+ $array->[$i] = Encode::decode($ie, $array->[$i]); | |
+ } | |
+ } | |
+ else { | |
+ $c->args->{$key} = Encode::decode($ie, $c->args->{$key}); | |
+ } | |
+ } | |
delete $c->req->env->{'plack.request.merged'}; # make sure | |
}); | |
$pkg->add_trigger( pre_finalize => sub { | |
diff -x .git -urN Pickles-origin/t/MyApp/etc/routes.pl Pickles/t/MyApp/etc/routes.pl | |
--- Pickles-origin/t/MyApp/etc/routes.pl 2011-02-18 18:52:18.000000000 +0900 | |
+++ Pickles/t/MyApp/etc/routes.pl 2011-02-18 19:57:15.000000000 +0900 | |
@@ -3,6 +3,10 @@ | |
connect '/foo' => { controller => 'Root', action => 'foo' }; | |
connect '/foo/bar' => { controller => 'Foo', action => 'bar' }; | |
connect '/foo/post' => { controller => 'Foo', action => 'post', }, { method => 'POST' }; | |
+ connect '/foo/multibyte_args/{ja}/' => { controller => 'Foo', action => 'multibyte_args', }; | |
+ connect qr{/foo/multibyte_array_args/(.+)/(.+)/} => { controller => 'Foo', action => 'multibyte_args', }; | |
+ | |
+ | |
connect '/redirect' => { controller => 'Root', action => 'redirect' }; | |
connect '/redirect2' => { controller => 'Root', action => 'redirect2' }; | |
connect '/redirect2' => { controller => 'Root', action => 'redirect2' }; | |
diff -x .git -urN Pickles-origin/t/MyApp/lib/MyApp/Controller/Foo.pm Pickles/t/MyApp/lib/MyApp/Controller/Foo.pm | |
--- Pickles-origin/t/MyApp/lib/MyApp/Controller/Foo.pm 2011-02-18 18:52:18.000000000 +0900 | |
+++ Pickles/t/MyApp/lib/MyApp/Controller/Foo.pm 2011-02-18 19:41:19.000000000 +0900 | |
@@ -2,6 +2,7 @@ | |
use strict; | |
use warnings; | |
use parent 'Pickles::Controller'; | |
+use Encode; | |
sub init { | |
my( $self, $c ) = @_; | |
@@ -24,6 +25,14 @@ | |
$c->finished(1); | |
} | |
+sub multibyte_args { | |
+ my( $self, $c ) = @_; | |
+ my $args = $c->args; | |
+ $c->res->content_type('text/plain'); | |
+ $c->res->body('ok'); | |
+ $c->finished(1); | |
+} | |
+ | |
1; | |
__END__ | |
diff -x .git -urN Pickles-origin/t/plugin/01_encode.t Pickles/t/plugin/01_encode.t | |
--- Pickles-origin/t/plugin/01_encode.t 2011-02-18 18:52:18.000000000 +0900 | |
+++ Pickles/t/plugin/01_encode.t 2011-02-18 20:00:57.000000000 +0900 | |
@@ -30,4 +30,27 @@ | |
like($c->res->body, qr/ライブドア/); | |
}; | |
+subtest 'multibyte_args' => sub { | |
+ use utf8; | |
+ my $req = HTTP::Request->new( GET => 'http://localhost/foo/multibyte_args/%E3%83%A9%E3%82%A4%E3%83%96%E3%83%89%E3%82%A2/' ); | |
+ my $env = $req->to_psgi; | |
+ my $c = MyApp->create_context( env => $env ); | |
+ $c->dispatch; | |
+ ok(utf8::is_utf8($c->args->{ja})); | |
+ is($c->args->{ja}, 'ライブドア') ; | |
+ no utf8; | |
+}; | |
+subtest 'multibyte_array_args' => sub { | |
+ use utf8; | |
+ my $req = HTTP::Request->new( GET => 'http://localhost/foo/multibyte_array_args/%E3%83%A9%E3%82%A4%E3%83%96%E3%83%89%E3%82%A2/%E3%83%A9%E3%82%A4%E3%83%96%E3%83%89%E3%82%A2/' ); | |
+ my $env = $req->to_psgi; | |
+ my $c = MyApp->create_context( env => $env ); | |
+ $c->dispatch; | |
+ for(@{$c->args->{splat}}){ | |
+ ok(utf8::is_utf8($_)); | |
+ is($_, 'ライブドア') ; | |
+ } | |
+ no utf8; | |
+}; | |
+ | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment