Skip to content

Commit

Permalink
Decoding utf8 parameters in request
Browse files Browse the repository at this point in the history
  • Loading branch information
Václav Novák committed Jul 31, 2012
1 parent b3e12c9 commit f43e04e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/WebNano/Controller.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 /;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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__
Expand Down

0 comments on commit f43e04e

Please sign in to comment.