Bugzilla – Attachment 184220 Details for
Bug 40424
Handling query-in-body relies on wrong data structure
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40424: Make query-in-body rely on `$c->req->json`
Bug-40424-Make-query-in-body-rely-on-c-req-json.patch (text/plain), 3.05 KB, created by
Matt Blenkinsop
on 2025-07-17 16:04:19 UTC
(
hide
)
Description:
Bug 40424: Make query-in-body rely on `$c->req->json`
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2025-07-17 16:04:19 UTC
Size:
3.05 KB
patch
obsolete
>From fade535d2fcf2d362d644239087750caafec8660 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 17 Jul 2025 11:54:00 -0300 >Subject: [PATCH] Bug 40424: Make query-in-body rely on `$c->req->json` > >This patch removes the reliance on `$c->validation->output` for the >query-in-body feature. This will allow bug 40417 to move forward. > >It also fixes some wrong design decisions we made 5-6 years ago. This >was discussed with the Mojolicious::Plugin::OpenAPI maintainer and the >agreement was `$c->validation->output` was not stable nor intended to be >accessed like we do. > >To test: >1. Run: > $ ktd --shell > k$ prove t/Koha/REST/Plugin/Query.t \ > t/db_dependent/api/v1/*.t \ > t/db_dependent/Koha/REST/Plugin/* >=> SUCCESS: Tests pass! >2. Apply this patchset >3. Repeat 1 >=> SUCCESS: Tests pass! >4. Sign off :-D > >Signed-off-by: Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> >--- > Koha/REST/Plugin/Objects.pm | 18 ++++++------------ > Koha/REST/Plugin/Query.pm | 2 +- > 2 files changed, 7 insertions(+), 13 deletions(-) > >diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm >index 753f3b8e6e5..59bede9a861 100644 >--- a/Koha/REST/Plugin/Objects.pm >+++ b/Koha/REST/Plugin/Objects.pm >@@ -216,28 +216,22 @@ controller, and thus shouldn't be called twice in it. > my $query_params; > > my $q_param = $reserved_params->{q}; >+ my $q_body = $c->req->json; > >- if ( $q_param >- || defined $reserved_params->{query} ) >- { >+ if ( $q_param || $q_body ) { > > my @query_params_array; > > my $json = JSON->new; > >- # query in request body, JSON::Validator already decoded it >- if ( $reserved_params->{query} ) { >- my $query = $json->encode( $reserved_params->{query} ); >- foreach my $qf ( @{$query_fixers} ) { >- $query = $qf->($query); >- } >- push @query_params_array, $json->decode($query); >- } >- > # The q parameter can be an array if multiple passed > $q_param = [$q_param] > unless ref($q_param) eq 'ARRAY'; > >+ # Encode the already decoded request body and add it for processing >+ push @{$q_param}, $json->encode($q_body) >+ if $q_body; >+ > foreach my $q ( @{$q_param} ) { > if ($q) { # skip if exists but is empty > foreach my $qf ( @{$query_fixers} ) { >diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm >index 93806ecf0b0..6f981bca1ca 100644 >--- a/Koha/REST/Plugin/Query.pm >+++ b/Koha/REST/Plugin/Query.pm >@@ -348,7 +348,7 @@ This helper method parses the 'x-koha-request-id' header and stashes the value. > > sub _reserved_words { > >- my @reserved_words = qw( _match _order_by _order_by[] _page _per_page q query); >+ my @reserved_words = qw( _match _order_by _order_by[] _page _per_page q ); > return \@reserved_words; > } > >-- >2.48.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40424
:
184208
|
184209
|
184210
|
184218
|
184219
|
184220
|
184554
|
184555
|
184556