From 50e5d6edae5711b767c4e40a47c8a381a88b8392 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Tue, 20 May 2025 12:37:54 +0000 Subject: [PATCH] Bug 39944: Trim form params Test plan, ktd, before applying patch: 1) Enable ILLModule sys pref and create a new ILL request: /cgi-bin/koha/ill/ill-requests.pl?method=create&backend=Standard 2) Pick type 'journal article' and enter ' 123' to DOI (notice the leading white space) 3) Enter a cardnumber and a library. Click 'Create'. 4) Run the following SQL query (koha-mysql kohadev): $ SELECT * from illrequestattributes where illrequest_id = '' and type ='doi'; 5) Notice the value is saved with the leading whitespace. Apply patch. Repeat. Notice it no longer saves with the leading white space. Sponsored-by: NHS England --- Koha/ILL/Request.pm | 24 ++++++++++++++++++++++++ ill/ill-requests.pl | 1 + 2 files changed, 25 insertions(+) diff --git a/Koha/ILL/Request.pm b/Koha/ILL/Request.pm index 9b151e3924c..d88c327e2f9 100644 --- a/Koha/ILL/Request.pm +++ b/Koha/ILL/Request.pm @@ -2298,6 +2298,30 @@ sub can_patron_place_ill_in_opac { return 1; } +=head3 trim_form_params + + my $params = trim_form_params($params); + + Trims $params. Needed to ensure submitted data is not saved with leading or trailing white spaces: + + This: + { + 'doi' => ' 123', + }; + + Becomes: + { + 'doi' => '123', + }; + +=cut + +sub trim_form_params { + my ( $self, $params ) = @_; + + return { map { $_ => $params->{$_} =~ s/^\s+|\s+$//gr } keys %$params }; +} + =head3 get_history_check_requests $self->get_history_check_requests(); diff --git a/ill/ill-requests.pl b/ill/ill-requests.pl index 0db9c09b1eb..f4b350b7f94 100755 --- a/ill/ill-requests.pl +++ b/ill/ill-requests.pl @@ -161,6 +161,7 @@ if ($backends_available) { # Ready to create ILL request } else { + $params = $request->trim_form_params($params); my $backend_result = $request->backend_create($params); # After creation actions -- 2.39.5