Skip to content

Commit

Permalink
resolve #126 [rt.cpan.org #89827] - fix url PATH_INFO
Browse files Browse the repository at this point in the history
substitution logic to not remove PATH_INFO if it is the same as
SCRIPT_NAME as some webservers (IIS) sometimes set PATH_INFO to
the same value as SCRIPT_NAME
  • Loading branch information
leejo committed Oct 17, 2014
1 parent a1ce47d commit 44ab08c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
charset force numeric encoding of all characters, because that does not
happen

[ SPEC / BUG FIXES ]
- don't sub out PATH_INFO in url if PATH_INFO is the same as SCRIPT_NAME
(RT #89827)

4.07 2014-10-12

[ RELEASE NOTES ]
Expand Down
8 changes: 7 additions & 1 deletion lib/CGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2947,7 +2947,13 @@ sub url {
my $uri = $rewrite && $request_uri ? $request_uri : $script_name;
$uri =~ s/\?.*$//s; # remove query string
$uri =~ s/\Q$ENV{PATH_INFO}\E$// if defined $ENV{PATH_INFO};
if ( defined( $ENV{PATH_INFO} ) ) {
# IIS sometimes sets PATH_INFO to the same value as SCRIPT_NAME so only sub it out
# if SCRIPT_NAME isn't defined or isn't the same value as PATH_INFO
$uri =~ s/\Q$ENV{PATH_INFO}\E$//
if ( ! defined( $ENV{SCRIPT_NAME} ) or $ENV{PATH_INFO} ne $ENV{SCRIPT_NAME} );
}
if ($full) {
my $protocol = $self->protocol();
Expand Down
9 changes: 9 additions & 0 deletions t/url.t
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ subtest 'RT#58377: + in PATH_INFO' => sub {
is($q->path_info(), '/hello+world', 'a plus sign in a script name is preserved when calling path_info()');
};

subtest 'IIS PATH_INFO eq SCRIPT_NAME' => sub {
local $ENV{PATH_INFO} = '/hello+world';
local $ENV{HTTP_X_FORWARDED_HOST} = undef;
local $ENV{HTTP_HOST} = 'example.com';
local $ENV{SCRIPT_NAME} = '/hello+world';

my $q = CGI->new;
is( $q->url,'http://example.com/hello+world','PATH_INFO being the same as SCRIPT_NAME');
};

done_testing();

Expand Down

0 comments on commit 44ab08c

Please sign in to comment.