From: Eric Wong Date: Sun, 1 Apr 2018 22:58:19 +0000 (+0000) Subject: searchview: fix non-numeric comparison X-Git-Tag: v1.1.0-pre1~23^2~3 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=3f3d9cf7d88a851721f1f8468e1311a4f0c02ff6 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. --- diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index bf4415f0..219006a0 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 1df38691..84b3daa3 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();