Change to decode args for in chained dispatch.
Tomas Doran [Tue, 26 May 2009 18:28:41 +0000 (18:28 +0000)]
merge -r 10290:10295 from branches/decode-chained-args

lib/Catalyst/DispatchType/Chained.pm
lib/Catalyst/Request.pm
t/aggregate/live_component_controller_action_chained.t
t/lib/TestApp/Controller/Action/Chained.pm

index 8600ac0..18e7c59 100644 (file)
@@ -151,7 +151,13 @@ sub match {
     my @parts = split('/', $path);
 
     my ($chain, $captures, $parts) = $self->recurse_match($c, '/', \@parts);
-    push @{$request->args}, @$parts if $parts && @$parts;
+
+    if ($parts && @$parts) {
+        for my $arg (@$parts) {
+            $arg =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
+            push @{$request->args}, $arg;
+        }
+    }
 
     return 0 unless $chain;
 
index 87b2012..dd1ce9c 100644 (file)
@@ -219,8 +219,7 @@ For example, if your action was
 and the URI for the request was C<http://.../foo/moose/bah>, the string C<bah>
 would be the first and only argument.
 
-Arguments just get passed through and B<don't> get unescaped automatically, so
-you should do that explicitly.
+Arguments get automatically URI-unescaped for you.
 
 =head2 $req->args
 
index 70b539d..9d83176 100644 (file)
@@ -10,7 +10,7 @@ our $iters;
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
 
-use Test::More tests => 145*$iters;
+use Test::More tests => 147*$iters;
 use Catalyst::Test 'TestApp';
 
 if ( $ENV{CAT_BENCHMARK} ) {
@@ -1009,7 +1009,13 @@ sub run_tests {
         ok( my $content =
             get('http://localhost/chained/return_arg/foo%2Fbar%3B'),
             'request with URI-encoded arg' );
-        # this is the CURRENT behavior
-        like( $content, qr{foo%2Fbar%3B\z}, 'args NOT decoded' );
+        like( $content, qr{foo/bar;\z}, 'args decoded' );
+    }
+    {
+        ok( my $content =
+            get('http://localhost/chained/return_arg_decoded/foo%2Fbar%3B'),
+            'request with URI-encoded arg' );
+        like( $content, qr{foo/bar;\z}, 'args decoded' );
     }
 }
+
index c3c85fe..051961c 100644 (file)
@@ -3,6 +3,8 @@ package TestApp::Controller::Action::Chained;
 use strict;
 use warnings;
 
+use HTML::Entities;
+
 use base qw/Catalyst::Controller/;
 
 sub begin :Private { }
@@ -196,6 +198,11 @@ sub star_search : Chained('view') PathPart('search') Args(0) { }
 sub doc_star : Chained('/') PathPart('chained/doc') Args(1) {}
 
 sub return_arg : Chained('/') PathPart('chained/return_arg') Args(1) {}
+sub return_arg_decoded : Chained('/') PathPart('chained/return_arg_decoded') Args(1) {
+    my ($self, $c) = @_;
+    $c->req->args([ map { decode_entities($_) } @{ $c->req->args }]);
+}
+
 
 sub end :Private {
   my ($self, $c) = @_;