Fix unquoted regex as per RT#24951
Tomas Doran [Sun, 18 Apr 2010 23:03:56 +0000 (23:03 +0000)]
Changes
lib/Catalyst/Engine/CGI.pm
t/aggregate/unit_core_engine_cgi-prepare_path.t

diff --git a/Changes b/Changes
index dec8e3c..2ec5d69 100644 (file)
--- a/Changes
+++ b/Changes
@@ -9,6 +9,8 @@
      ->cleanup feature. (RT#41442)
    - Ensure that Catalyst::Engine::HTTP's options hash is defined before
      dereferencing it. (RT#49267)
+   - Fix regex special characters in REDIRECT_URL variable breaking
+     the request base. (2nd part of RT#24951)
 
   New features:
    - Setting __PACKAGE__->config(enable_catalyst_header => 1); in your MyApp.pm
index de9fe2d..f9f9fa8 100644 (file)
@@ -123,7 +123,7 @@ sub prepare_path {
     my $base_path;
     if ( exists $ENV{REDIRECT_URL} ) {
         $base_path = $ENV{REDIRECT_URL};
-        $base_path =~ s/$ENV{PATH_INFO}$//;
+        $base_path =~ s/\Q$ENV{PATH_INFO}\E$//;
     }
     else {
         $base_path = $script_name || '/';
index 39281cd..c604487 100644 (file)
@@ -97,6 +97,21 @@ use Catalyst::Engine::CGI;
     is ''.$r->base, 'http://www.foo.com/tx/';
 }
 
+# test req->base and c->uri_for work correctly after an internally redirected request
+# (i.e. REDIRECT_URL set) when the PATH_INFO contains a regex
+{
+    my $path = '/engine/request/uri/Rx(here)';
+    my $r = get_req (
+        SCRIPT_NAME => '/',
+        PATH_INFO => $path,
+        REQUEST_URI => $path,
+        REDIRECT_URL => $path,
+    );
+
+    is $r->path, 'engine/request/uri/Rx(here)', 'URI contains correct path';
+    is $r->base, 'http://www.foo.com/', 'Base is correct';
+}
+
 
 # FIXME - Test proxy logic
 #       - Test query string