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 <tomascohen@theke.io>
This commit is contained in:
Tomás Cohen Arazi 2023-07-06 15:50:40 -03:00
parent f3cc00d945
commit d90d264253
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -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
}
}
}