fixed problem with overlapping server path and request path when testing on a non...
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Test.pm
index 20bd827..3aa9878 100644 (file)
@@ -153,6 +153,29 @@ sub remote_request {
         $request->uri->path(join '/', @rp);
     }
 
+    # the request path needs to be sanitised if $server is using a
+    # non-root path due to potential overlap between request path and
+    # response path.
+    if ($server->path) {
+        # If request path is '/', we have to add a trailing slash to the
+        # final request URI
+        my $add_trailing = $request->uri->path eq '/';
+        
+        my @sp = split '/', $server->path;
+        my @rp = split '/', $request->uri->path;
+        shift @sp;shift @rp; # leading /
+        if (@rp) {
+            foreach my $sp (@sp) {
+                $sp eq $rp[0] ? shift @rp : last
+            }
+        }
+        $request->uri->path(join '/', @rp);
+        
+        if ( $add_trailing ) {
+            $request->uri->path( $request->uri->path . '/' );
+        }
+    }
+
     $request->uri->scheme( $server->scheme );
     $request->uri->host( $server->host );
     $request->uri->port( $server->port );