From e45c91d53f249b01dce43bf9224b891dfa304942 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 25 Mar 2016 16:46:24 -0400 Subject: [PATCH] LP#1562153: fix case where changing sort order to relevance can fail This patch fixes a cause where sending a 'sort' CGI parameter with the empty string as value (which specifies relevance sorting) fails to override a previously-set sort order. To test: [1] Do a public catalog search starting from the advanced search form, e.g., keyword = "cats" [2] Change the sort order to (say) Title A-Z from the results page. [3] Note that the query string changes to "sort(titlesort) cats" and that the results are re-sorted [4] Attempt to change the sort order to relevance. [5] This time, the sort order does not change ... and it should have. [6] Apply the patch and repeat steps 1-5. This time, the sort order should be successfully changed. Signed-off-by: Galen Charlton Signed-off-by: Mike Rylander --- Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm index ecd1bad8ae..51bdf238e2 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -120,15 +120,18 @@ sub _prepare_biblio_search { return () unless $query; # sort is treated specially, even though it's actually a filter - if ($cgi->param('sort')) { + if (defined($cgi->param('sort'))) { $query =~ s/sort\([^\)]*\)//g; # override existing sort(). no stacking. my ($axis, $desc) = split /\./, $cgi->param('sort'); - $query = "sort($axis) $query"; + $query = "sort($axis) $query" if $axis; if ($desc and not $query =~ /\#descending/) { $query = "#descending $query"; } elsif (not $desc) { $query =~ s/\#descending//; } + # tidy up + $query =~ s/^\s+//; + $query =~ s/\s+$//; } my (@naive_query_re, $site); -- 2.11.0