user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: Jonathan Corbet <corbet@lwn.net>
Subject: [PATCH] searchview: fix non-numeric comparison
Date: Sun, 1 Apr 2018 23:22:17 +0000	[thread overview]
Message-ID: <20180401232217.GA28379@dcvr> (raw)
In-Reply-To: <20180401232111.GA25534@dcvr>

Eric Wong <e@80x24.org> wrote:
> I noticed another minor problem, but will followup in a separate
> patch.

Subject: [PATCH] searchview: fix non-numeric comparison

We don't want non-fully-numeric limits being compared and
tripping warnings.  While we're at it, avoid hard-coding
'200' and reuse $LIM as the default.
---
 lib/PublicInbox/SearchView.pm | 6 ++----
 t/psgi_search.t               | 6 ++++++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index bf4415f..219006a 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -309,10 +309,8 @@ sub new {
 	my ($class, $qp) = @_;
 
 	my $r = $qp->{r};
-	my $l = $qp->{l} || '200';
-	if (! ($l =~ /(\d+)/ && $l <= $LIM)) {
-		$l = $LIM;
-	}
+	my ($l) = (($qp->{l} || '') =~ /(\d+)/);
+	$l = $LIM if !$l || $l > $LIM;
 	bless {
 		q => $qp->{'q'},
 		x => $qp->{x} || '',
diff --git a/t/psgi_search.t b/t/psgi_search.t
index 1df3869..84b3daa 100644
--- a/t/psgi_search.t
+++ b/t/psgi_search.t
@@ -64,6 +64,12 @@ test_psgi(sub { $www->call(@_) }, sub {
 	is('%C3%86var', (keys %uniq)[0], 'matches original query');
 	ok(index($html, 'by &#198;var Arnfj&#246;r&#240; Bjarmason') >= 0,
 		"displayed Ævar's name properly in HTML");
+
+	my $warn = [];
+	local $SIG{__WARN__} = sub { push @$warn, @_ };
+	$res = $cb->(GET('/test/?q=s:test&l=5e'));
+	is($res->code, 200, 'successful search result');
+	is_deeply([], $warn, 'no warnings from non-numeric comparison');
 });
 
 done_testing();
-- 
EW

      reply	other threads:[~2018-04-01 23:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-30 21:25 [PATCH v2] Jonathan Corbet
2018-04-01 23:21 ` [PATCH v2] Allow specification of the number of search results to return Eric Wong
2018-04-01 23:22   ` Eric Wong [this message]

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=20180401232217.GA28379@dcvr \
    --to=e@80x24.org \
    --cc=corbet@lwn.net \
    --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 public 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).