More tests for the prepare_path thing, fix said tests, changelog
Tomas Doran [Wed, 9 Dec 2009 20:54:53 +0000 (20:54 +0000)]
Changes
lib/Catalyst/Engine/CGI.pm
t/aggregate/unit_core_engine_cgi-prepare_path.t

diff --git a/Changes b/Changes
index 868d4c5..b0b442e 100644 (file)
--- a/Changes
+++ b/Changes
@@ -9,6 +9,10 @@
      than listening on all interfaces, which was the previous default. (Dave
      Rolsky)
    - Fix the script environment variables MYAPP_PORT and MYAPP_RELOAD RT#52604
+   - Fix aliasing applications under non-root paths with mod_rewrite in
+     some apache versions where %ENV{SCRIPT_NAME} is set to the real name of
+     the script, by using $ENV{REDIRECT_URL} which contains the non-rewritten
+     URI.
 
   New features:
    - The __MOP__ hash element is suppressed from being dumped fully
index 8fa1fca..f00268b 100644 (file)
@@ -108,6 +108,8 @@ sub prepare_headers {
 
 =cut
 
+# Please don't touch this method without adding tests in
+# t/aggregate/unit_core_engine_cgi-prepare_path.t
 sub prepare_path {
     my ( $self, $c ) = @_;
     local (*ENV) = $self->env || \%ENV;
@@ -153,9 +155,7 @@ sub prepare_path {
     # Here we try to resurrect the original encoded URI from REQUEST_URI.
     my $path_info   = $ENV{PATH_INFO};
     if (my $req_uri = $ENV{REQUEST_URI}) {
-        if (defined $script_name) {
-            $req_uri =~ s/^\Q$script_name\E//;
-        }
+        $req_uri =~ s/^\Q$base_path\E//;
         $req_uri =~ s/\?.*$//;
         $path_info = $req_uri if $req_uri;
     }
index 845b22f..0c874e5 100644 (file)
@@ -6,19 +6,58 @@ use lib "$Bin/../lib";
 use TestApp;
 use Catalyst::Engine::CGI;
 
+my %template = (
+    HTTP_HOST => 'www.foo.com',
+    PATH_INFO => '/',
+);
+
+# mod_rewrite to app root for non / based app
 {
-    our %ENV = (
-        HTTP_HOST => 'www.foo.com',
+    my $r = get_req (
         REDIRECT_URL => '/comics/',
-        PATH_INFO => '/',
         SCRIPT_NAME => '/comics/dispatch.cgi',
         REQUEST_URI => '/comics/',
     );
+    is ''.$r->uri, 'http://www.foo.com/comics/';
+    is ''.$r->base, 'http://www.foo.com/comics/';
+}
+
+# mod_rewrite to sub path under app root for non / based app
+{
+    my $r = get_req (
+        PATH_INFO  => '/foo/bar.gif',
+        REDIRECT_URL => '/comics/foo/bar.gif',
+        SCRIPT_NAME => '/comics/dispatch.cgi',
+        REQUEST_URI => '/comics/foo/bar.gif',
+    );
+    is ''.$r->uri, 'http://www.foo.com/comics/foo/bar.gif';
+    is ''.$r->base, 'http://www.foo.com/comics/';
+}
+
+# Standard CGI hit for non / based app
+{
+    my $r = get_req (
+        PATH_INFO => '/static/css/blueprint/screen.css',
+        SCRIPT_NAME => '/~bobtfish/Gitalist/script/gitalist.cgi',
+        REQUEST_URI => '/~bobtfish/Gitalist/script/gitalist.cgi/static/css/blueprint/screen.css',
+    );
+    is ''.$r->uri, 'http://www.foo.com/~bobtfish/Gitalist/script/gitalist.cgi/static/css/blueprint/screen.css';
+    is ''.$r->base, 'http://www.foo.com/~bobtfish/Gitalist/script/gitalist.cgi/';
+}
+
+# FIXME - Test proxy logic
+#       - Test encoding/escaping
+#       - Test query string
+#       - Test non standard port numbers
+#       - Test // in PATH_INFO
+#       - Test scheme (secure request on port 80)
+
+sub get_req {
+    local %ENV = (%template, @_);
     my $i = TestApp->new;
     $i->engine(Catalyst::Engine::CGI->new);
     $i->engine->prepare_path($i);
-    is ''.$i->req->uri, 'http://www.foo.com/comics/';
-    is ''.$i->req->base, 'http://www.foo.com/comics/';
+    return $i->req;
 }
 
 done_testing;