Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove the multiple slashes fix from the FCGI handler into middleware.

This code was originally added in:

commit 5a22236
commit 2af4bb5

however causes a load of problems if applied unconditionally,
and so is removed from the core FCGI handler into a middleware here.
  • Loading branch information...
commit e4cf55589a99658657f462f9d2c175120b7ce5bd 1 parent 343d295
@bobtfish authored
View
5 lib/Plack/Handler/FCGI.pm
@@ -111,11 +111,6 @@ sub run {
delete $env->{HTTP_CONTENT_TYPE};
delete $env->{HTTP_CONTENT_LENGTH};
- # lighttpd munges multiple slashes in PATH_INFO into one. Try recovering it
- my $uri = URI->new("http://localhost" . $env->{REQUEST_URI});
- $env->{PATH_INFO} = uri_unescape($uri->path);
- $env->{PATH_INFO} =~ s/^\Q$env->{SCRIPT_NAME}\E//;
-
if ($env->{SERVER_SOFTWARE} && $env->{SERVER_SOFTWARE} =~ m!lighttpd[-/]1\.(\d+\.\d+)!) {
no warnings;
if ($ENV{PLACK_ENV} eq 'development' && $1 < 4.23 && $env->{PATH_INFO} eq '') {
View
51 lib/Plack/Middleware/FixPathInfoMultipleSlashes.pm
@@ -0,0 +1,51 @@
+package Plack::Middleware::FixPathInfoMultipleSlashes;
+
+use strict;
+use parent 'Plack::Middleware';
+use URI::Escape;
+use URI;
+
+sub call {
+ my($self, $env) = @_;
+
+ # lighttpd and apache munge multiple slashes in PATH_INFO into one. Try recovering it
+ my $uri = URI->new("http://localhost" . $env->{REQUEST_URI});
+ $env->{PATH_INFO} = uri_unescape($uri->path);
+ $env->{PATH_INFO} =~ s/^\Q$env->{SCRIPT_NAME}\E//;
+
+ return $self->app->($env);
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Plack::Middleware::FixPathInfoMultipleSlashes - fixes wrong PATH_INFO that lighttpd and apache generate by munging multiple slashes to one
+
+=head1 SYNOPSIS
+
+ # in your app.psgi
+ use Plack::Builder;
+
+ builder {
+ enable "FixPathInfoMultipleSlashes";
+ $app;
+ };
+
+ # Or from the command line
+ plackup -s FCGI -e 'enable "FixPathInfoMultipleSlashes"' /path/to/app.psgi
+
+=head1 DESCRIPTION
+
+This middleware fixes wrong C<PATH_INFO> set by lighttpd and apache which munge multiple slashes to a single slash.
+
+This middleware is not applied automatically, as it can break use of mod_rewrite when prepending things to the C<PATH_INFO>.
+
+=head1 AUTHORS
+
+Tomas Doran, Tatsuhiko Miyagawa, cho45
+
+=cut
+
View
5 lib/Plack/Middleware/IIS6ScriptNameFix.pm
@@ -2,12 +2,15 @@ package Plack::Middleware::IIS6ScriptNameFix;
use strict;
use parent 'Plack::Middleware';
+use URI::Escape;
+use URI;
sub call {
my($self, $env) = @_;
if ($env->{SERVER_SOFTWARE} && $env->{SERVER_SOFTWARE} =~ /IIS\/[6-9]\.[0-9]/) {
- my @script_name = split(m!/!, $env->{PATH_INFO});
+ my $uri = URI->new("http://localhost" . $env->{REQUEST_URI});
+ my @script_name = split(m!/!, uri_unescape($uri->path));
my @path_translated = split(m!/|\\\\?!, $env->{PATH_TRANSLATED});
my @path_info;
View
19 lib/Plack/Test/Suite.pm
@@ -710,25 +710,6 @@ our @TEST = (
];
},
],
- [
- 'repeated slashes',
- sub {
- my $cb = shift;
- my $res = $cb->(GET "http://127.0.0.1//foo///bar/baz");
- is $res->code, 200;
- is $res->message, 'OK';
- is $res->header('content_type'), 'text/plain';
- is $res->content, '//foo///bar/baz';
- },
- sub {
- my $env = shift;
- return [
- 200,
- [ 'Content-Type' => 'text/plain', ],
- [ $env->{PATH_INFO} ],
- ];
- },
- ],
);
sub runtests {
View
63 t/Plack-Middleware/fcgi_path_info_multipleslashes_fix.t
@@ -0,0 +1,63 @@
+use strict;
+use warnings;
+use Test::More;
+
+use Plack::Middleware::FixPathInfoMultipleSlashes;
+use URI::Escape;
+use URI;
+
+my %env = (
+ 'psgi.multiprocess' => 1,
+ 'SCRIPT_NAME' => '/fastcgi',
+ 'PATH_INFO' => '/foo/bar/baz',
+ 'REQUEST_METHOD' => 'GET',
+ 'psgi.multithread' => '',
+ 'SCRIPT_FILENAME' => '/var/folders/9y/f64sy2xx3vnb8ddv4w1g498m0000gn/T/utzt7PlANx/fastcgi',
+ 'SERVER_SOFTWARE' => 'lighttpd/1.4.30',
+ 'HTTP_TE' => 'deflate,gzip;q=0.3',
+ 'REMOTE_PORT' => '54624',
+ 'QUERY_STRING' => '',
+ 'HTTP_USER_AGENT' => 'libwww-perl/6.04',
+ 'FCGI_ROLE' => 'RESPONDER',
+ 'psgi.streaming' => 1,
+ 'GATEWAY_INTERFACE' => 'CGI/1.1',
+ 'psgi.version' => [
+ 1,
+ 1
+ ],
+ 'DOCUMENT_ROOT' => '/var/folders/9y/f64sy2xx3vnb8ddv4w1g498m0000gn/T/utzt7PlANx/',
+ 'psgi.run_once' => '',
+ 'PATH_TRANSLATED' => '/var/folders/9y/f64sy2xx3vnb8ddv4w1g498m0000gn/T/utzt7PlANx//foo/bar/baz',
+ 'SERVER_NAME' => '127.0.0.1',
+ 'HTTP_CONNECTION' => 'TE, close',
+ 'SERVER_PORT' => '50992',
+ 'REDIRECT_STATUS' => '200',
+ 'REMOTE_ADDR' => '127.0.0.1',
+ 'SERVER_PROTOCOL' => 'HTTP/1.1',
+ 'REQUEST_URI' => '/fastcgi//foo///bar/baz',
+ 'psgi.nonblocking' => '',
+ 'SERVER_ADDR' => '127.0.0.1',
+ 'psgi.url_scheme' => 'http',
+ 'psgix.harakiri' => 1,
+ 'HTTP_X_PLACK_TEST' => '35',
+ 'HTTP_HOST' => '127.0.0.1:50992',
+);
+
+sub test_fix {
+ my ($input_env) = @_;
+
+ my $mangled_env;
+ Plack::Middleware::FixPathInfoMultipleSlashes->wrap(sub {
+ my ($env) = @_;
+ $mangled_env = $env;
+ return [ 200, ['Content-Type' => 'text/plain'], [''] ];
+ })->($input_env);
+
+ return $mangled_env;
+}
+
+my $fixed_env = test_fix({ %env });
+
+is($fixed_env->{PATH_INFO}, '//foo///bar/baz', 'check PATH_INFO');
+
+done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.