]> Sergey Matveev's repositories - public-inbox.git/commitdiff
cgi: relax path restriction for top-level
authorEric Wong <e@80x24.org>
Sat, 12 Apr 2014 00:49:34 +0000 (00:49 +0000)
committerEric Wong <e@80x24.org>
Sat, 12 Apr 2014 00:49:34 +0000 (00:49 +0000)
We may have something like /foo.cgi/m/$MID.html in there.

public-inbox.cgi
t/cgi.t

index 6a6f31e23ef81acd8045001190a3e7991c012290..fb435777c666b987f8a6bc085dae3b923852d6fc 100755 (executable)
@@ -16,7 +16,7 @@ use CGI qw(:cgi :escapeHTML -nosticky); # PSGI/FastCGI/mod_perl compat
 use Encode qw(decode_utf8);
 use PublicInbox::Config;
 use Digest::SHA qw(sha1_hex);
-our $LISTNAME_RE = qr!\A/([\w\.\-]+)!;
+our $LISTNAME_RE = qr!\A(?:/.*?)?/([\w\.\-]+)!;
 our $pi_config;
 BEGIN {
        $pi_config = PublicInbox::Config->new;
@@ -55,7 +55,7 @@ sub main {
        # top-level indices and feeds
        if ($path_info eq "/") {
                r404();
-       } elsif ($path_info =~ m!$LISTNAME_RE(?:/|/index\.html)?\z!o) {
+       } elsif ($path_info =~ m!$LISTNAME_RE/(?:index\.html)?\z!o) {
                invalid_list(\%ctx, $1) || get_index(\%ctx, $cgi, 1);
        } elsif ($path_info =~ m!$LISTNAME_RE/index\.atom\.xml\z!o) {
                invalid_list(\%ctx, $1) || get_atom(\%ctx, $cgi, 1);
diff --git a/t/cgi.t b/t/cgi.t
index a66c582520ecf0190194ebd2e55bc7f7505da257..39242bce12ea95d110c6cfcdb8132462e0603b19 100644 (file)
--- a/t/cgi.t
+++ b/t/cgi.t
@@ -131,6 +131,10 @@ EOF
        my $res = cgi_run("/test/m/blahblah\@example.com.txt");
        like($res->{body}, qr/Message-Id: <blahblah\@example\.com>/,
                "mid.txt hit");
+
+       my $pfx = cgi_run("/prefixed/test/m/blahblah\@example.com.txt");
+       is_deeply($pfx, $res, "we do not have to be a top-level URL");
+
        $res = cgi_run("/test/m/blahblah\@example.con.txt");
        like($res->{head}, qr/Status: 404 Not Found/, "mid.txt miss");