]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www_listing: fix odd "locate inbox" cases
authorEric Wong <e@80x24.org>
Fri, 27 Aug 2021 12:08:45 +0000 (12:08 +0000)
committerEric Wong <e@80x24.org>
Sat, 28 Aug 2021 10:37:10 +0000 (10:37 +0000)
Searching inboxes with an empty query no longer gives 500 errors
due to Xapian.  Also, improve the error message when no inboxes
match, since saying no inboxes exist yet is wrong.

lib/PublicInbox/WwwListing.pm
t/extindex-psgi.t

index eabda98abe484bebc0ff41276de648e91675f8bc..1bb5fbd041587cbc3931d370fcecde9519d5ff6e 100644 (file)
@@ -96,7 +96,8 @@ sub add_misc_ibx { # MiscSearch->retry_reopen callback
 
        delete $ctx->{-list}; # reset if retried
        my $pi_cfg = $ctx->{www}->{pi_cfg};
-       if (defined(my $user_query = $q->{'q'})) {
+       my $user_query = $q->{'q'} // '';
+       if ($user_query =~ /\S/) {
                $qs = "( $qs ) AND ( $user_query )";
        } else { # special case for ALL
                $ctx->ibx_entry($pi_cfg->ALL // die('BUG: ->ALL expected'), {});
@@ -218,6 +219,10 @@ sub psgi_triple {
                $gzf->zmore('<pre>');
                $gzf->zmore(join("\n", @$list));
                $gzf->zmore(mset_footer($ctx, $mset)) if $mset;
+       } elsif (my $mset = delete $ctx->{-mset}) {
+               $gzf->zmore(mset_nav_top($ctx, $mset));
+               $gzf->zmore('<pre>no matching inboxes');
+               $gzf->zmore(mset_footer($ctx, $mset));
        } else {
                $gzf->zmore('<pre>no inboxes, yet');
        }
index 31b04acd40cebfad4003d73bbd47141b6e98f6be..4e26962e06c923b4b31901933eed61854bf3d07d 100644 (file)
@@ -59,8 +59,14 @@ my $client = sub {
        is($res->code, 200, 'all.mbox.gz');
 
        $res = $cb->(GET('/'));
-       my $html = $res->content;
-       like($html, qr!\Qhttp://bogus.example.com/all\E!, 'html shows /all');
+       like($res->content, qr!\Qhttp://bogus.example.com/all\E!,
+               '/all listed');
+       $res = $cb->(GET('/?q='));
+       is($res->code, 200, 'no query means all inboxes');
+       $res = $cb->(GET('/?q=nonexistent'));
+       is($res->code, 404, 'no inboxes matched');
+       unlike($res->content, qr!no inboxes, yet!,
+               'we have inboxes, just no matches');
 };
 test_psgi(sub { $www->call(@_) }, $client);
 %$env = (%$env, TMPDIR => $tmpdir, PI_CONFIG => $pi_config);