Subject: | [PATCH] Catalyst::Engine::CGI misbehaves when REDIRECT_URL is set but PATH_INFO is not |
[This is actually against 5.7006, but RT doesn't show that version...]
My ISP allows persistent apps only via .fcgi files (via Apache
mod_fastcgi). To avoid seeing "index.fcgi" in the URL, I use the
following in my .htaccess
RewriteRule ^(.*)$ index.fcgi [QSA,L]
That correctly sets $ENV{REDIRECT_URL} (to, say, "/about") but leaves
$ENV{PATH_INFO} undefined. Consequently the $c->req->base url is not
computed correctly, and $c->uri_for() goes haywire. The attached patch
detects this scenario and does the following:
* sets the $base_path to the dir of the $ENV{SCRIPT_NAME}
* computes the missing $ENV{PATH_INFO} by using $ENV{REDIRECT_URL}
minus the newly-computed base
I'm not sure that this is the best possible solution, but it works for me.
Note that I've wrapped the s/// variables in \Q...\E to prevent
interpretation of, say ".*" characters in the URL.
Subject: | engine-cgi.patch |
--- /home/equilibrious/SALG/par/lib/Catalyst/Engine/CGI.pm 2007-02-14 09:06:16.000000000 -0800
+++ /home/equilibrious/SALG/lib/Catalyst/Engine/CGI.pm 2007-02-14 09:30:03.000000000 -0800
@@ -116,7 +116,12 @@
my $base_path;
if ( exists $ENV{REDIRECT_URL} ) {
$base_path = $ENV{REDIRECT_URL};
- $base_path =~ s/$ENV{PATH_INFO}$//;
+ if ($ENV{PATH_INFO}) {
+ $base_path =~ s/\Q$ENV{PATH_INFO}\E$//;
+ } elsif ($ENV{SCRIPT_NAME}) {
+ ($base_path = $ENV{SCRIPT_NAME}) =~ s{[^/]+\z}{}xms;
+ ($ENV{PATH_INFO} = $ENV{REDIRECT_URL}) =~ s{\A\Q$base_path\E}{}xms;
+ }
}
else {
$base_path = $ENV{SCRIPT_NAME} || '/';