From d90d264253134a1c6fa7dbb64b959bd7d3789fce Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 6 Jul 2023 15:50:40 -0300 Subject: [PATCH] Bug 33974: (follow-up) _order_by is not always an arrayref The loop through the `_order_by` query parameter occurences introduced by this patchset was naive regarding the possible scenarios. When there's only one parameter passed, it shouldn't be expecting an arrayref, but a scalar. This patch deals with that in the simplest way. To test: 1. Run: $ ktd --shell k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t => FAIL: Tests are failing 2. Apply this patch 3. Repeat 1 => SUCCESS: Tests pass! 4. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- Koha/REST/Plugin/Objects.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm index f09bf70bd6..512010dd81 100644 --- a/Koha/REST/Plugin/Objects.pm +++ b/Koha/REST/Plugin/Objects.pm @@ -161,10 +161,15 @@ controller, and thus shouldn't be called twice in it. $c->extract_reserved_params($args); if ( exists $reserved_params->{_order_by} ) { + + # convert to arrayref if it is a single param, to keep code simple + $reserved_params->{_order_by} = [ $reserved_params->{_order_by} ] + unless ref( $reserved_params->{_order_by} ) eq 'ARRAY'; + # _order_by passed, fix if required - for my $p ( @{$reserved_params->{_order_by}} ) { + for my $p ( @{ $reserved_params->{_order_by} } ) { foreach my $qf ( @{$query_fixers} ) { - $p = $qf->($p, 1); # 1 => no quotes on matching + $p = $qf->( $p, 1 ); # 1 => no quotes on matching } } } -- 2.39.5