Skip to content

Commit

Permalink
Merge 828f446 into 349a5b7
Browse files Browse the repository at this point in the history
  • Loading branch information
rrthomas committed Oct 18, 2017
2 parents 349a5b7 + 828f446 commit 4deaec6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/CGI.pm
Expand Up @@ -2688,11 +2688,11 @@ sub url {
my $request_uri = $self->request_uri || '';
my $query_str = $query ? $self->query_string : '';

$script_name =~ s/\?.*$//s; # remove query string
$request_uri =~ s/\?.*$//s; # remove query string
$request_uri = unescape($request_uri);

my $uri = $rewrite && $request_uri ? $request_uri : $script_name;
$uri =~ s/\?.*$//s; # remove query string

if ( defined( $ENV{PATH_INFO} ) ) {
# IIS sometimes sets PATH_INFO to the same value as SCRIPT_NAME so only sub it out
Expand Down
12 changes: 12 additions & 0 deletions t/url.t
Expand Up @@ -95,6 +95,18 @@ subtest 'IIS PATH_INFO eq SCRIPT_NAME' => sub {
is( $q->url,'http://example.com/hello+world','PATH_INFO being the same as SCRIPT_NAME');
};

subtest 'Escaped question marks preserved' => sub {
local $ENV{HTTP_X_FORWARDED_HOST} = undef;
local $ENV{HTTP_HOST} = 'example.com';
local $ENV{PATH_INFO} = '/path/info';
local $ENV{REQUEST_URI} = '/real/path/info%3F';
local $ENV{SCRIPT_NAME} = '/real/cgi-bin/dispatch.cgi';
local $ENV{SCRIPT_FILENAME} = '/home/mark/real/path/cgi-bin/dispatch.cgi';

my $q = CGI->new;
is( $q->url(-absolute=>1), '/real/path/info?' );
};

done_testing();


0 comments on commit 4deaec6

Please sign in to comment.