Bug 17526: Change grep to deal with malformed sortfield
authorMark Tompsett <mtompset@hotmail.com>
Thu, 13 Jun 2019 19:27:00 +0000 (19:27 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 18 Jun 2019 09:03:54 +0000 (10:03 +0100)
Giving sortfield a malformed value when viewing lists results in
Internal Server Error.

eg.
http://localhost:8080/cgi-bin/koha/opac-shelves.pl?op=view&shelfnumber=1&sortfield=title(

Note the trailing (

Before Patch: kaboom
apply patch
restart
After Patch: No kaboom

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

opac/opac-shelves.pl

index d235292..cca12f2 100755 (executable)
@@ -235,7 +235,7 @@ if ( $op eq 'view' ) {
         if ( $shelf->can_be_viewed( $loggedinuser ) ) {
             $category = $shelf->category;
             my $sortfield = $query->param('sortfield') || $shelf->sortfield;    # Passed in sorting overrides default sorting
-            $sortfield = 'title' unless grep {/^$sortfield$/}qw( title author copyrightdate itemcallnumber dateadded );
+            $sortfield = 'title' unless grep $_ eq $sortfield, qw( title author copyrightdate itemcallnumber dateadded );
             my $direction = $query->param('direction') || 'asc';
             $direction = 'asc' if $direction ne 'asc' and $direction ne 'desc';
             my ( $page, $rows );