From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) 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.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A94BD1F404; Sun, 1 Apr 2018 23:22:17 +0000 (UTC) Date: Sun, 1 Apr 2018 23:22:17 +0000 From: Eric Wong To: meta@public-inbox.org Cc: Jonathan Corbet Subject: [PATCH] searchview: fix non-numeric comparison Message-ID: <20180401232217.GA28379@dcvr> References: <20180330152557.1604c836@lwn.net> <20180401232111.GA25534@dcvr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180401232111.GA25534@dcvr> List-Id: Eric Wong 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 Ævar Arnfjörð 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