From de9665f27886c0447dcea5dc4f4f7359163f4895 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 18 Sep 2024 09:49:50 +0200 Subject: [PATCH] Bug 37902: Apply exact match for datetime We do not want to apply "like" and do a "contains" search if a correctly formatted date is passed (ie. starting with "YYYY-MM-DD HH:MM:SS") It causes underlying problems if we add '%' characters to this string as it will then become an invalid date. There are several ways of dealing with this problem. This patch is suggesting the easiest path: Apply an exact search (ie. do not add '%') if the value appears to be a datetime. Certainly not the best looking patch but it seems to be quite effective: * no need to change the client * no need to rework build_query_params, merge_q_params, attributes_from_api We could (to confirm) pass the result set, but it seems a lot of additional processing (that is done later already, in attributes_from_api) Signed-off-by: Nick Clemens --- Koha/REST/Plugin/Query.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm index c8ba09e8d49..fe3d936df97 100644 --- a/Koha/REST/Plugin/Query.pm +++ b/Koha/REST/Plugin/Query.pm @@ -195,7 +195,10 @@ is raised. my $match = $reserved_params->{_match} // 'contains'; foreach my $param ( keys %{$filtered_params} ) { - if ( $match eq 'contains' ) { + if ( $match eq 'exact' || $filtered_params->{$param} =~ m[^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}]) { + $params->{$param} = $filtered_params->{$param}; + } + elsif ( $match eq 'contains' ) { $params->{$param} = { like => '%' . $filtered_params->{$param} . '%' }; } @@ -205,9 +208,6 @@ is raised. elsif ( $match eq 'ends_with' ) { $params->{$param} = { like => '%' . $filtered_params->{$param} }; } - elsif ( $match eq 'exact' ) { - $params->{$param} = $filtered_params->{$param}; - } else { # We should never reach here, because the OpenAPI plugin should # prevent invalid params to be passed -- 2.39.5