From 2f59ccfc99fae00556ce73d67db761192480bcb1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 17 Mar 2021 09:43:49 +0100 Subject: [PATCH] Bug 27933: [ALTERNATIVE PATCH] Fix patron search result ordering --- C4/Utils/DataTables.pm | 4 ++-- t/db_dependent/Utils/Datatables.t | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/C4/Utils/DataTables.pm b/C4/Utils/DataTables.pm index 6e1af15611..a2f62dc447 100644 --- a/C4/Utils/DataTables.pm +++ b/C4/Utils/DataTables.pm @@ -104,8 +104,8 @@ sub dt_build_orderby { return unless @orderbys; - # Must be "branches.branchname asc", "borrowers.firstname desc", etc. - @orderbys = grep { /^\w+\.\w+ (asc|desc)$/ } @orderbys; + # Must be "branches.branchname asc", "borrowers.firstname desc", "dateofbirth asc" etc. + @orderbys = grep { /^\w*\.?\w+ (asc|desc)$/ } @orderbys; my @sanitized_orderbys; for my $orderby (@orderbys) { diff --git a/t/db_dependent/Utils/Datatables.t b/t/db_dependent/Utils/Datatables.t index ae0c61bc4e..7f6dde40d4 100755 --- a/t/db_dependent/Utils/Datatables.t +++ b/t/db_dependent/Utils/Datatables.t @@ -32,7 +32,7 @@ $schema->storage->txn_begin; my $builder = t::lib::TestBuilder->new; subtest 'dt_build_orderby' => sub { - plan tests => 2; + plan tests => 3; my $dt_params = { iSortCol_0 => 5, @@ -58,4 +58,14 @@ subtest 'dt_build_orderby' => sub { $orderby = dt_build_orderby($dt_params); is( $orderby, " ORDER BY `branches`.`branchname` ASC,`borrowers`.`surname` DESC,`borrowers`.`firstname` DESC ", 'ORDER BY has been correctly built, even with invalid stuff'); + + $dt_params = { + iSortCol_0 => 1, + sSortDir_0 => "asc", + mDataProp_1 => "dateofbirth", + name_sorton => "dateofbirth asc", + }; + + $orderby = dt_build_orderby($dt_params); + is( $orderby, " ORDER BY `dateofbirth` ASC ", 'ORDER BY has been correctly built' ); }; -- 2.20.1