Permalink
Browse files

Decoding utf8 parameters in request

  • Loading branch information...
1 parent b3e12c9 commit f43e04e99fac9b75106381ab1d8024e94ecc3c78 Václav Novák committed Jul 31, 2012
Showing with 12 additions and 0 deletions.
  1. +12 −0 lib/WebNano/Controller.pm
View
@@ -5,6 +5,7 @@ package WebNano::Controller;
use URI::Escape 'uri_unescape';
use Plack::Request;
+use Encode;
use WebNano::FindController 'find_nested';
use Object::Tiny::RW qw/ app env self_url url_map _req path /;
@@ -15,6 +16,8 @@ sub req {
my $self = shift;
return $self->_req if defined $self->_req;
my $req = Plack::Request->new( $self->env );
+ _decode_parameters($req->query_parameters);
+ _decode_parameters($req->body_parameters);
$self->_req( $req );
return $req;
}
@@ -92,6 +95,15 @@ sub handle {
sub search_subcontrollers { 0 }
+sub _decode_parameters {
+ my ($multihash) = @_;
+ for my $key (keys %$multihash) {
+ my @vals = $multihash->get_all($key);
+ $multihash->remove($key);
+ $multihash->set(decode_utf8($key), map decode_utf8($_), @vals);
+ }
+}
+
1;
__END__

0 comments on commit f43e04e

Please sign in to comment.