From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id D17EC1F8C8 for ; Fri, 27 Aug 2021 12:08:45 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/2] www_listing: fix odd "locate inbox" cases Date: Fri, 27 Aug 2021 12:08:45 +0000 Message-Id: <20210827120845.29682-3-e@80x24.org> In-Reply-To: <20210827120845.29682-1-e@80x24.org> References: <20210827120845.29682-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 7 ++++++- t/extindex-psgi.t | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm index eabda98a..1bb5fbd0 100644 --- a/lib/PublicInbox/WwwListing.pm +++ b/lib/PublicInbox/WwwListing.pm @@ -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('
');
 		$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('
no matching inboxes');
+		$gzf->zmore(mset_footer($ctx, $mset));
 	} else {
 		$gzf->zmore('
no inboxes, yet');
 	}
diff --git a/t/extindex-psgi.t b/t/extindex-psgi.t
index 31b04acd..4e26962e 100644
--- a/t/extindex-psgi.t
+++ b/t/extindex-psgi.t
@@ -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);