Bugzilla – Attachment 183261 Details for
Bug 40128
StripWhitespaceChars can create empty subfields
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40128: StripWhitespaceChars can create empty subfields
Bug-40128-StripWhitespaceChars-can-create-empty-su.patch (text/plain), 2.33 KB, created by
Roman Dolny
on 2025-06-15 12:19:26 UTC
(
hide
)
Description:
Bug 40128: StripWhitespaceChars can create empty subfields
Filename:
MIME Type:
Creator:
Roman Dolny
Created:
2025-06-15 12:19:26 UTC
Size:
2.33 KB
patch
obsolete
>From c00e684f417be02715d3d3342e791ab3e5c4770e Mon Sep 17 00:00:00 2001 >From: Janusz Kaczmarek <januszop@gmail.com> >Date: Sat, 14 Jun 2025 21:45:32 +0000 >Subject: [PATCH] Bug 40128: StripWhitespaceChars can create empty subfields > >When StripWhitespaceChars is enabled and the user by chance enters >some white spaces in the input field, Koha generates empty subfield >(or even entirely empty field). > >Test plan: >========== >1. Enable StripWhitespaceChars system preference. >2. Edit an existing record, putting just some spaces into an empty > subfield. Save the record. >3. Go to bibliographic record Normal view and in modal "MARC preview" > notice that the subfield you entered spaces in exists as an empty > subfield. If it was the only subfield in a field, the field exists > with no data at all. This is wrong. >4. Apply the patch ; restart_all. >5. Repeat 2. and 3. You should not see any empty subfield now. If the > empty subbfield was the only subfield in a field, the field should > have been removed from the record. > >Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl> >--- > Koha/Filter/MARC/TrimFields.pm | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > >diff --git a/Koha/Filter/MARC/TrimFields.pm b/Koha/Filter/MARC/TrimFields.pm >index 99a5f0dfa3..00244cab29 100644 >--- a/Koha/Filter/MARC/TrimFields.pm >+++ b/Koha/Filter/MARC/TrimFields.pm >@@ -60,9 +60,15 @@ sub filter { > my $value = $subfield->[1]; > $value =~ s/[\n\r]+/ /g; > $value =~ s/^\s+|\s+$//g; >- $field->add_subfields( $key => $value ); # add subfield to the end of the subfield list >- $field->delete_subfield( pos => 0 ); # delete the subfield at the top of the subfield list >+ $field->add_subfields( $key => $value ) >+ if $value ne q{} >+ ; # add subfield to the end of the subfield list, but only if there is still a non empty value there >+ $field->delete_subfield( pos => 0 ); # delete the subfield at the top of the subfield list > } >+ >+ # if it happed that all existing subfields had whitespaces only, >+ # the field would be empty now and should be removed from the record >+ $record->delete_fields($field) unless scalar( $field->subfields ); > } > } > return $record; >-- >2.39.5
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 40128
:
183259
|
183260
| 183261 |
183262