Patch for uri_for_action with regex dispatch from RT#39369
Tomas Doran [Tue, 28 Apr 2009 21:41:51 +0000 (21:41 +0000)]
Changes
lib/Catalyst/DispatchType/Regex.pm
t/aggregate/live_component_controller_action_regexp.t
t/lib/TestApp/Controller/Action/Regexp.pm

diff --git a/Changes b/Changes
index 588730c..12a750c 100644 (file)
--- a/Changes
+++ b/Changes
@@ -19,6 +19,8 @@
         - Additional tests for setup_stats method. (t0m)
         - Fix log levels in Catalyst::Log to be properly additive. (t0m)
         - Fix RT#43375 by sorting results before testing them (t0m)
+        - Fixes for uri_for_action when using Catalyst::DispatchType::Regex
+          + tests from RT#39369 (norbi)
 
 5.80002 2009-04-22 01:28:36
         - Fix CATALYST_DEBUG and MYAPP_DEBUG environment variables
index 0b6f97c..1c0c59e 100644 (file)
@@ -150,11 +150,13 @@ sub uri_for_action {
             my $final = '/';
             my @captures = @$captures;
             while (my ($front, $rest) = split(/\(/, $re, 2)) {
+                last unless defined $rest;
                 ($rest, $re) =
                     Text::Balanced::extract_bracketed("(${rest}", '(');
                 next REGEX unless @captures;
                 $final .= $front.shift(@captures);
             }
+            $final .= $re;
             next REGEX if @captures;
             return $final;
          }
index ab5d4ba..2697940 100644 (file)
@@ -10,7 +10,7 @@ our $iters;
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
 
-use Test::More tests => 33*$iters;
+use Test::More tests => 38*$iters;
 use Catalyst::Test 'TestApp';
 
 use Catalyst::Request;
@@ -118,4 +118,24 @@ sub run_tests {
             'Test Class'
         );
     }
+    
+    {
+        my $url = 'http://localhost/action/regexp/redirect/life/universe/42/everything';
+        ok( my $response = request($url),
+            'Request' );
+        ok( $response->is_redirect, 'Response is redirect' );
+        is( $response->header('X-Catalyst-Action'),
+            '^action/regexp/redirect/(\w+)/universe/(\d+)/everything$', 'Test Action' );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Action::Regexp',
+            'Test Class'
+        );
+        is(
+            $response->header('location'),
+            $url,
+            'Redirect URI is the same as the request URI'
+        );
+    }
 }
+
index cdb6abc..4b59d58 100644 (file)
@@ -18,4 +18,13 @@ sub three : Action LocalRegex('^(mandatory)(/optional)?$'){
     $c->forward('TestApp::View::Dump::Request');
 }
 
+sub four : Action Regex('^action/regexp/redirect/(\w+)/universe/(\d+)/everything$') {
+    my ( $self, $c ) = @_;
+    $c->res->redirect(
+        $c->uri_for($c->action, $c->req->captures,
+            @{$c->req->arguments}, $c->req->params
+        )
+    );
+}
+
 1;