Permalink
Browse files

Unescape and decode path arguments

  • Loading branch information...
1 parent 1395f92 commit d9135ecc0077a749dcb7c4b5756a2cc5c7a0dc8c @spiritloose committed Aug 13, 2009
Showing with 18 additions and 1 deletion.
  1. +10 −0 lib/Schenker.pm
  2. +8 −1 t/05_route.t
View
@@ -5,6 +5,8 @@ use Any::Moose;
use Carp qw(croak);
use Scalar::Util qw(blessed);
use Path::Class qw(file dir);
+use Encode qw(decode);
+use URI::Escape qw(uri_unescape);
use Schenker::Router;
use Schenker::Engine;
use Schenker::Templates;
@@ -247,6 +249,13 @@ sub send_file {
halt $body;
}
+sub decode_args {
+ my $args = shift;
+ while (my ($key, $val) = each %$args) {
+ $args->{$key} = decode(options->encode->{decode}, uri_unescape($val));
+ }
+}
+
sub run_action {
my $rule = shift;
my $action = $rule->{action};
@@ -321,6 +330,7 @@ sub dispatch {
eval {
my $rule = Schenker::Router->match($req) or route_missing;
parse_nested_query;
+ decode_args($rule->{args});
run_before_filters($rule);
run_action($rule);
};
View
@@ -1,5 +1,5 @@
package MyApp;
-use Test::More tests => 10;
+use Test::More tests => 11;
use Schenker;
use HTTP::Request::Common qw(GET HEAD POST PUT DELETE);
@@ -21,6 +21,11 @@ get '/foo/:foo' => sub {
$args->{foo};
};
+get '/decode/:arg' => sub {
+ my $args = shift;
+ ok(utf8::is_utf8($args->{arg}));
+};
+
put '/bar' => sub {
'put /bar'
};
@@ -57,6 +62,8 @@ like($res->content, qr{delete /});
$res = Schenker::run(GET 'http://localhost/foo/bar');
like($res->content, qr{bar});
+$res = Schenker::run(GET 'http://localhost/decode/%263a');
+
$res = Schenker::run(POST 'http://localhost/bar?_method=PUT');
like($res->content, qr{put /bar});

0 comments on commit d9135ec

Please sign in to comment.