From: Alex J. G. BurzyƄski Date: Wed, 21 Apr 2010 11:10:51 +0000 (+0000) Subject: Fix not stripping backslashes in DispatchType::Regex::uri_for_action X-Git-Tag: 5.80023~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=b1cb1951d47533ecf9ccd52aaac1d02f051cf205 Fix not stripping backslashes in DispatchType::Regex::uri_for_action --- diff --git a/Changes b/Changes index 2ec5d69..aef1516 100644 --- 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 diff --git a/lib/Catalyst/DispatchType/Regex.pm b/lib/Catalyst/DispatchType/Regex.pm index 0d6da04..4b1beae 100644 --- a/lib/Catalyst/DispatchType/Regex.pm +++ b/lib/Catalyst/DispatchType/Regex.pm @@ -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)) { diff --git a/t/aggregate/unit_core_uri_for_action.t b/t/aggregate/unit_core_uri_for_action.t index 4431f5a..ccc5910 100644 --- a/t/aggregate/unit_core_uri_for_action.t +++ b/t/aggregate/unit_core_uri_for_action.t @@ -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 # diff --git a/t/lib/TestApp/Controller/Action/Regexp.pm b/t/lib/TestApp/Controller/Action/Regexp.pm index 4b59d58..7966874 100644 --- a/t/lib/TestApp/Controller/Action/Regexp.pm +++ b/t/lib/TestApp/Controller/Action/Regexp.pm @@ -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;