Bug 40156: Advanced editor should not create empty fields and subfields

Currently, advanced bibliographic records editor creates empty
subfields (or even empty fields) when no content is placed after
‡<code> (or, in case of control fields, after <tag>).

Test plan:
==========
1. Enable EnableAdvancedCatalogingEditor (have StripWhitespaceChars
   set to "Don't strip" - the default setting).
2. Open a record in the advanced editor, create empty subfield and
   empty fields, e.g.:

007
500 _ _ ‡a
246 3 1 ‡aAdditional title :‡b

3. Save the record. Go to bibliographic record Normal view and in
   modal "MARC preview" notice that the fields / subfields you entered as
   empty exist in the record with no data. This is wrong.
4. Apply the patch ; restart_all.
5. Repeat p. 2 and 3. Note that empty fields/subfields have not been
   created.

Sponsored-by: Ignatianum University in Cracow
Signed-off-by: Wojciech Baran <wojciech.baran@ignatianum.edu.pl>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit d56b15d29c)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Janusz Kaczmarek 2025-06-17 10:15:31 +00:00 committed by Paul Derscheid
parent cd788e34ed
commit 3a22c2efb2
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
1 changed files with 13 additions and 6 deletions

View File

@ -58,9 +58,11 @@ define( [ 'marc-record' ], function( MARC ) {
tagNumber = tagNumber[1];
if ( tagNumber < '010' ) {
var field = new MARC.Field( tagNumber, ' ', ' ', [ [ '@', line.substring( 4 ) ] ] );
field.sourceLine = i;
record.addField( field );
if (line.length > 4) {
var field = new MARC.Field(tagNumber, ' ', ' ', [['@', line.substring(4)]]);
field.sourceLine = i;
record.addField(field);
}
} else {
var indicators = line.match( /^... ([0-9A-Za-z_ ]) ([0-9A-Za-z_ ])/ );
if ( !indicators ) {
@ -86,12 +88,17 @@ define( [ 'marc-record' ], function( MARC ) {
$.each( subfields, function( i, subfield ) {
var next = subfields[ i + 1 ];
field.addSubfield( [ subfield.code, line.substring( subfield.ch + 2, next ? next.ch : line.length ) ] );
var subfield_start = subfield.ch + 2;
var subfield_end = (next ? next.ch : line.length);
if (subfield_end > subfield_start) {
field.addSubfield( [ subfield.code, line.substring( subfield_start, subfield_end ) ] );
}
} );
field.sourceLine = i;
record.addField( field );
if (field.subfields().length) {
record.addField( field );
}
}
} );