From 3e10d0765414a8268abfb077efd091afb615558c Mon Sep 17 00:00:00 2001
From: Aleisha Amohia <aleishaamohia@hotmail.com>
Date: Wed, 27 Apr 2022 22:53:47 +0000
Subject: [PATCH] Bug 30358: (follow-up) Consider field has multiple subfields
 of same key

To test:

1) Click the clone subfield button to make multiple subfields with the
same key, i.e. 500$a$a$a
2) Save the record and confirm that the fields contain the correct data
after whitespaces are stripped.

Signed-off-by: David Nind <david@davidnind.com>
---
 C4/Biblio.pm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index 2ed6aa8617..6aafa6ac0b 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -2759,7 +2759,8 @@ sub ModBiblioMarc {
                 my $value = $subfield->[1];
                 $value =~ s/[\n\r]+/ /g;
                 $value =~ s/^\s+|\s+$|^\t+|\t+$//g;
-                $field->update( $key => $value );
+                $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
             }
         }
     }
-- 
2.30.2