]> Sergey Matveev's repositories - public-inbox.git/commitdiff
searchview: fix non-numeric comparison
authorEric Wong <e@80x24.org>
Sun, 1 Apr 2018 22:58:19 +0000 (22:58 +0000)
committerEric Wong <e@80x24.org>
Sun, 1 Apr 2018 23:04:20 +0000 (23:04 +0000)
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
t/psgi_search.t

index bf4415f011b8ea79603a1de8c4da348b312e9d08..219006a0d7070dbfc58530255eba7aeba1919ff4 100644 (file)
@@ -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} || '',
index 1df38691c1c07a1b3eb825683d691325c3be1316..84b3daa3402ac071b4562addc70ef3e6e547e71d 100644 (file)
@@ -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();