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>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit d0ce815600)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
parent
d212c89d81
commit
f48cb7a0f0
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue