From: Tomas Doran Date: Wed, 9 Dec 2009 20:54:53 +0000 (+0000) Subject: More tests for the prepare_path thing, fix said tests, changelog X-Git-Tag: 5.80016~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=eb3abf9698d6eb550497284482f36a315e856091 More tests for the prepare_path thing, fix said tests, changelog --- diff --git a/Changes b/Changes index 868d4c5..b0b442e 100644 --- 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 diff --git a/lib/Catalyst/Engine/CGI.pm b/lib/Catalyst/Engine/CGI.pm index 8fa1fca..f00268b 100644 --- a/lib/Catalyst/Engine/CGI.pm +++ b/lib/Catalyst/Engine/CGI.pm @@ -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; } diff --git a/t/aggregate/unit_core_engine_cgi-prepare_path.t b/t/aggregate/unit_core_engine_cgi-prepare_path.t index 845b22f..0c874e5 100644 --- a/t/aggregate/unit_core_engine_cgi-prepare_path.t +++ b/t/aggregate/unit_core_engine_cgi-prepare_path.t @@ -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;