Commit c23bd70a authored by IKEDA Soji's avatar IKEDA Soji
Browse files

Small fix.

parent 1bcdd695
...@@ -242,7 +242,7 @@ sub get_robot { ...@@ -242,7 +242,7 @@ sub get_robot {
my $request_path = $org_script_name . $org_path_info; my $request_path = $org_script_name . $org_path_info;
# Find mail domain (a.k.a. "robot") of which web URL matches script-URI. # Find mail domain (a.k.a. "robot") of which web URL matches script-URI.
my ($robot_id, $script_path) = (undef, ''); my ($robot_id, $script_path) = (undef, undef);
foreach my $rid (Sympa::List::get_robots()) { foreach my $rid (Sympa::List::get_robots()) {
my $local_url; my $local_url;
foreach my $key (@keys) { foreach my $key (@keys) {
...@@ -266,15 +266,16 @@ sub get_robot { ...@@ -266,15 +266,16 @@ sub get_robot {
and grep { $uri->scheme eq $_ } qw(http https); and grep { $uri->scheme eq $_ } qw(http https);
my $host = lc URI::Escape::uri_unescape($uri->host // ''); my $host = lc URI::Escape::uri_unescape($uri->host // '');
my $path = URI::Escape::uri_unescape($uri->path // '/'); my $path = URI::Escape::uri_unescape($uri->path // '');
next unless $request_host eq $host; next unless $request_host eq $host;
next next
unless $request_path eq $path unless $request_path eq $path
or 0 == index($request_path, $path . '/'); or 0 == index $request_path, $path . '/';
# The longest path wins. # The longest path wins.
($robot_id, $script_path) = ($rid, $path) ($robot_id, $script_path) = ($rid, $path)
if length $script_path < length $path; if not defined $script_path
or length $script_path < length $path;
} }
return unless $robot_id; return unless $robot_id;
......
...@@ -73,5 +73,21 @@ $ENV{PATH_INFO} = 'help'; ...@@ -73,5 +73,21 @@ $ENV{PATH_INFO} = 'help';
is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')], [], is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')], [],
'dubious PATH_INFO'; 'dubious PATH_INFO';
$Conf::Conf{wwsympa_url} = 'http://web.example.org';
$ENV{SERVER_NAME} = 'web.example.org';
$ENV{SCRIPT_NAME} = '';
$ENV{PATH_INFO} = '/help';
is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')],
['mail.example.org', '', '/help'],
'URL prefix on the top: (empty) SCRIPT_NAME & non-empty PATH_INFO';
$ENV{SERVER_NAME} = 'web.example.org';
$ENV{SCRIPT_NAME} = '/help';
$ENV{PATH_INFO} = undef;
is_deeply [Sympa::WWW::Tools::get_robot('wwsympa_url')],
['mail.example.org', '', '/help'],
'URL prefix on the top: no PATH_INFO';
done_testing(); done_testing();
rmtree 't/tmp'; rmtree 't/tmp';
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment