Fix paths with URI encoding as the first path part
Tomas Doran [Thu, 28 Jan 2010 15:47:31 +0000 (15:47 +0000)]
Changes
lib/Catalyst/Engine/CGI.pm
t/aggregate/unit_core_engine_cgi-prepare_path.t

diff --git a/Changes b/Changes
index d2d16d6..7832e73 100644 (file)
--- a/Changes
+++ b/Changes
@@ -12,6 +12,9 @@
      an action object has been fixed to not just encode the first slash in
      any set of args/captures.
 
+   - nginx and lighttpd FCGI requests with URI encoded sections as the first
+     path part have been fixed to operate correctly.
+
   New features:
    - Allow passing additional arguments to action constructors.
 
index 1443a2f..4c0d9b9 100644 (file)
@@ -168,7 +168,8 @@ sub prepare_path {
             if (substr($req_uri, 0, 1) ne '/') {
                 my ($match) = $req_uri =~ m|^([^/]+)|;
                 my ($path_info_part) = $path_info =~ m|^(.*?\Q$match\E)|;
-                substr($req_uri, 0, length($match), $path_info_part);
+                substr($req_uri, 0, length($match), $path_info_part)
+                    if $path_info_part;
             }
             $path_info = $req_uri;
         }
index f8b08ef..22081ff 100644 (file)
@@ -62,7 +62,17 @@ use Catalyst::Engine::CGI;
     is ''.$r->base, 'http://www.foo.com/';
 }
 
-
+# nginx example from espent with path /"foo"
+{
+    my $r = get_req (
+        PATH_INFO => '"foo"',
+        SCRIPT_NAME => '/',
+        REQUEST_URI => '/%22foo%22',
+    );
+    is ''.$r->path, '%22foo%22';
+    is ''.$r->uri, 'http://www.foo.com/%22foo%22';
+    is ''.$r->base, 'http://www.foo.com/';
+}
 
 # FIXME - Test proxy logic
 #       - Test query string