From b81cdf7c052edbd6e0ad3334370e57d1ef9a0c16 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 11 Mar 2021 11:15:26 +0100 Subject: [PATCH] Bug 27760: Improve readabiliity using map --- Koha/REST/Plugin/Query.pm | 11 ++--------- t/Koha/REST/Plugin/Query.t | 6 +++++- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm index d6ad18dfe11..d01d64d8fe0 100644 --- a/Koha/REST/Plugin/Query.pm +++ b/Koha/REST/Plugin/Query.pm @@ -277,16 +277,9 @@ Merges parameters from $q_params into $filtered_params. my ( $c ) = @_; - my $override_header = $c->req->headers->header('x-koha-override'); + my $override_header = $c->req->headers->header('x-koha-override') || q{}; - my $overrides = {}; - - if ( $override_header ) { - my @overrides = (); - foreach my $override ( split /\s*,\s*/, $override_header ) { - $overrides->{$override} = 1; - } - } + my $overrides = { map { $_ => 1 } split /\s*,\s*/, $override_header }; $c->stash( 'koha.overrides' => $overrides ); diff --git a/t/Koha/REST/Plugin/Query.t b/t/Koha/REST/Plugin/Query.t index f5580d0cc24..c52914a7bfd 100755 --- a/t/Koha/REST/Plugin/Query.t +++ b/t/Koha/REST/Plugin/Query.t @@ -502,7 +502,7 @@ subtest 'stash_embed() tests' => sub { subtest 'stash_overrides() tests' => sub { - plan tests => 4; + plan tests => 6; my $t = Test::Mojo->new; @@ -511,4 +511,8 @@ subtest 'stash_overrides() tests' => sub { $t->get_ok( '/stash_overrides' => { 'x-koha-override' => '' } ) ->json_is( {} ); # empty string is skipped + + $t->get_ok( '/stash_overrides' => { } ) + ->json_is( {} ); # x-koha-ovverride not passed is skipped + }; -- 2.31.1