Fix not stripping backslashes in DispatchType::Regex::uri_for_action
Alex J. G. BurzyƄski [Wed, 21 Apr 2010 11:10:51 +0000 (11:10 +0000)]
Changes
lib/Catalyst/DispatchType/Regex.pm
t/aggregate/unit_core_uri_for_action.t
t/lib/TestApp/Controller/Action/Regexp.pm

diff --git a/Changes b/Changes
index 2ec5d69..aef1516 100644 (file)
--- a/Changes
+++ b/Changes
@@ -11,6 +11,7 @@
      dereferencing it. (RT#49267)
    - Fix regex special characters in REDIRECT_URL variable breaking
      the request base. (2nd part of RT#24951)
+   - Fix not stripping backslashes in DispatchType::Regex::uri_for_action
 
   New features:
    - Setting __PACKAGE__->config(enable_catalyst_header => 1); in your MyApp.pm
index 0d6da04..4b1beae 100644 (file)
@@ -151,6 +151,7 @@ sub uri_for_action {
             my $re = "$orig";
             $re =~ s/^\^//;
             $re =~ s/\$$//;
+            $re =~ s/\\([^\\])/$1/g;
             my $final = '/';
             my @captures = @$captures;
             while (my ($front, $rest) = split(/\(/, $re, 2)) {
index 4431f5a..ccc5910 100644 (file)
@@ -8,7 +8,7 @@ use lib "$FindBin::Bin/../lib";
 
 use Test::More;
 
-plan tests => 30;
+plan tests => 33;
 
 use_ok('TestApp');
 
@@ -54,6 +54,21 @@ is($dispatcher->uri_for_action($regex_action, [ 'foo', 123 ]),
    "/action/regexp/foo/123",
    "Regex action interpolates captures correctly");
 
+my $regex_action_bs = $dispatcher->get_action_by_path(
+                     '/action/regexp/one_backslashes'
+                   );
+
+ok(!defined($dispatcher->uri_for_action($regex_action_bs)),
+   "Regex action without captures returns undef");
+
+ok(!defined($dispatcher->uri_for_action($regex_action_bs, [ 1, 2, 3 ])),
+   "Regex action with too many captures returns undef");
+
+is($dispatcher->uri_for_action($regex_action_bs, [ 'foo', 123 ]),
+   "/action/regexp/foo/123.html",
+   "Regex action interpolates captures correctly");
+
+
 #
 #   Index Action
 #
index 4b59d58..7966874 100644 (file)
@@ -27,4 +27,9 @@ sub four : Action Regex('^action/regexp/redirect/(\w+)/universe/(\d+)/everything
     );
 }
 
+sub one_backslashes : Action Regex('^action/regexp/(\w+)/(\d+)\.html$') {
+    my ( $self, $c ) = @_;
+    $c->forward('TestApp::View::Dump::Request');
+}
+
 1;