user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
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	[thread overview]
Message-ID: <20210827120845.29682-3-e@80x24.org> (raw)
In-Reply-To: <20210827120845.29682-1-e@80x24.org>

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('<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');
 	}
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);

  parent reply	other threads:[~2021-08-27 12:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26 17:01 Add a way to search all from wwwlisting Konstantin Ryabitsev
2021-08-27 12:08 ` [PATCH 0/2] wwwlisting shows /all/ Eric Wong
2021-08-27 12:08   ` [PATCH 1/2] www_listing: show ->ALL at top of HTML listing Eric Wong
2021-08-27 12:08   ` Eric Wong [this message]
2021-08-27 13:03   ` [PATCH 0/2] wwwlisting shows /all/ Konstantin Ryabitsev
2021-08-27 14:33     ` Konstantin Ryabitsev
2021-08-27 22:03       ` [PATCH] www: avoid potential auto-vivification on ibx->{url} Eric Wong
2021-08-28 18:00         ` Konstantin Ryabitsev
2021-08-27 21:15     ` [PATCH 0/2] wwwlisting shows /all/ Eric Wong
2021-09-26  1:30   ` [PATCH] www_listing: support /all/ search as a 302 redirect Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210827120845.29682-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).